Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Verify if a PDF is secured/protected with iTextSharp

Tags:

c#

pdf

itextsharp

Is it possible to verify if we can copy the content of a PDF document with iTextSharp?

I have a method that copy the content of the PDF and add a new page at the end with project's information but it throw a "System.ArgumentException: PdfReader not opened with owner password". I get this error when I do writer.GetImportedPage(reader, i);

Thanks for the help!

like image 611
VinnyG Avatar asked Jan 18 '23 20:01

VinnyG


1 Answers

You should be able to just check the property PdfReader.IsOpenedWithFullPermissions.

PdfReader r = new PdfReader("YourFile.pdf");
if (r.IsOpenedWithFullPermissions)
{
    //Do something
}
like image 200
Chris Haas Avatar answered Jan 31 '23 08:01

Chris Haas