-1

I found out that I got an error if I try to open an existing 1.6 PDF with iText (version 5.1.1). If I transform this same PDF in a 1.5, I'm able to read it.

I tried to find out since which version of iText PDF 1.6 are handled but cannot find the information. Any idea? Thx!

Edit: here the stack :

Caused by: java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1OctetString
    at com.itextpdf.text.pdf.PdfEncryption.<init>(PdfEncryption.java:147)
    at com.itextpdf.text.pdf.PdfReader.readDecryptedDocObj(PdfReader.java:775)
    at com.itextpdf.text.pdf.PdfReader.readDocObj(PdfReader.java:1152)
    at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:512)
    at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:172)

Error is happening when executing line :

final PdfReader reader = new PdfReader(file.getAbsolutePath());
Lempkin
  • 1,458
  • 2
  • 26
  • 49
  • Can you reproduce the error with iText 5.5.13? Can you share the PDF? Can you share the complete stack trace of _an error_? – Amedee Van Gasse Sep 20 '18 at 12:39
  • I've edited my post to add the stack, and yes I tried with 5.5.13 and still have same error – Lempkin Sep 20 '18 at 12:59
  • iText 5.1.1 is old, but it can perfectly deal with PDF 1.6 files. Chances are that your PDF has some flaw that is fixed when you convert it to a PDF 1.5 file. You could easily convert it to a PDF 1.7 file and it would also work. Your question is incomplete because you don't share your PDF, you don't share your code, and you don't even share an error message. – Bruno Lowagie Sep 20 '18 at 13:00
  • I cannot share the PDF as it's a personnal document (not mine). I've edited my question – Lempkin Sep 20 '18 at 13:04
  • 1
    http://www.orimi.com/pdf-test.pdf here is also a 1.6 PDF which is giving same error. – Lempkin Sep 20 '18 at 13:22
  • The PDF 1.6 file that you have is an encrypted file. When you convert it to another version, you remove the encryption. You can solve this problem by adding the correct version of the BouncyCastle library to your project. You mention a third party (your customer?); please note that there are some restrictions in place when using iText for free. You are only allowed to distribute your software with iText for free if you also distribute your own software for free under the same license (that is: the AGPL). – Bruno Lowagie Sep 20 '18 at 14:59

1 Answers1

2

Your question is misleading because you make a false allegation. You claim that the version of iText that you are using doesn't support PDF 1.6.

However, the error message you added in the edited version of your question shows the real cause:

Caused by: java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1OctetString

I opened the PDF you shared in the comment in Acrobat Reader, and this is what I saw:

enter image description here

You can clearly read:

The document's Security Method restrict what can be done to the document. To remove security restrictions, set the Security Method to No Security.

That is exactly what you did when you converted the original PDF that was compliant with PDF 1.6 to a document that is compliant with PDF 1.5. If you had removed the security restrictions and kept the file as a PDF 1.6 document, the problem wouldn't have occurred.

This being said. You don't need to remove the security restrictions. You can solve the java.lang.NoClassDefFoundError by adding the correct version of the BouncyCastle library to your CLASSPATH. You may have to change the unethicalreading variable to true as explained here: How to read PDFs created with an unknown random owner password?

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165