5

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!

VinnyG
  • 6,883
  • 7
  • 58
  • 76
  • "System.ArgumentException: PdfReader not opened with owner password" - are you opening the pdf with the owners password? If not that would be your first step, if you are then that exception is misleading. – Jeremy Thompson Aug 31 '11 at 01:07
  • I don't have the password, I want to verify if a password is needed because a user can upload any PDF and I need to verify if I can copy this PDF. – VinnyG Aug 31 '11 at 01:14

1 Answers1

9

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

PdfReader r = new PdfReader("YourFile.pdf");
if (r.IsOpenedWithFullPermissions)
{
    //Do something
}
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
  • I'm using a stream from an uploaded files and when I verify on the pdfreader it break my pdf, do I need to return to position 0 on my stream or close anything so I can save my stream without any problem? – VinnyG Sep 13 '11 at 20:44
  • Ok that's it, I had to put position back to 0 – VinnyG Sep 13 '11 at 20:55