41

With reference to this

http://stackoverflow.com/questions/17524857/merging-pdf-in-asp-net-c-sharp/17525948?noredirect=1#comment25485091_17525948 

question of mine, I have user IText for merging the pdf documents. I am getting " PdfReader not opened with owner password " for some files. Any suggestions

Ankur
  • 1,023
  • 7
  • 27
  • 42
  • 1
    Open it with the owner password? – Adriaan Stander Jul 17 '13 at 04:16
  • 1
    @astander : I don't have any password for the PDF file. – Ankur Jul 17 '13 at 06:25
  • @Ankur Not having the password means not being entitled to do what you try to do. – mkl Jul 17 '13 at 06:41
  • 1
    @Ankur If you are entitled, though, and merely forgot the owner password or the permissions should allow the operation in question, you might be interested in [this answer](http://stackoverflow.com/a/17694943/1729265). – mkl Jul 17 '13 at 08:46
  • 4
    @mkl I have the same issue, I have no password and the PDF opens nicely in all PDF readers I have (Acrobat, Foxit, Chrome), but fails with this message in iText. – Joel Peltonen Apr 10 '14 at 05:54
  • 1
    Have you tried the trick I pointed to in my latest comment? If you did and it did not work, please supply the PDF in question. – mkl Apr 10 '14 at 22:31

2 Answers2

88

Add this code after PdfReader definition

PdfReader.unethicalreading = true;

Mesut Başaran
  • 947
  • 6
  • 12
  • 4
    Thanks! Worked like a charm Not sure why it would be unethical to open a file via iTextSharp if I can open it otherwise without any warning or issues :) – Pradeep Nov 16 '15 at 06:24
  • for Itext7 the function is as follows: var reader = iText.Kernel.Pdf.PdfReader) and then reader.SetUnethicalReading(true); – Cees Aug 30 '22 at 01:49
17

For iText 7 it is

PdfReader pdfReader = new PdfReader(PATH + name + ".pdf");
pdfReader.setUnethicalReading(true);

See also: itext7-how-decrypt-pdf-document-owner-password

Ray Hulha
  • 10,701
  • 5
  • 53
  • 53
  • 2
    Don't forget that the `PdfReader` is disposable and it should be disposed afterwards or use the `using` statement – 321X Sep 03 '21 at 14:17
  • for c# you need an uppercase method name so: PdfReader pdfReader = new PdfReader(PATH + name + ".pdf"); pdfReader.SetUnethicalReading(true); – tappetyclick Jul 13 '22 at 13:10