I'm developing a little tool to watermark PDFs and it works for some PDFs and crashes for some others.
I'm using iText library and bouncycastle (dependency)
pom.xml:
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.6</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.49</version>
</dependency>
It crashes at this line (the very first line of code):
PdfReader reader = new PdfReader(src);
With the following stacktrace:
Exception in thread "main" com.itextpdf.text.exceptions.InvalidPdfException: class "org.bouncycastle.asn1.ASN1Primitive"'s signer information does not match signer information of other classes in the same package
at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:727)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:181)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:219)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:207)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:197)
... <from here it points to my code>
I've done some googling and some people say that possibly the problem is that I have this bouncycastle lib duplicated somewhere.
This is inside an Spring application build with Maven. So, can this really be a library problem?
I'm using JDK 1.8.
What I've tried:
- Different bouncycastle versions with Maven.
- Different bouncycastle versions (supporting my JDK version) added manually to the project (including iText).
But the behaviour is exactly the same, some PDF works (always) and some others don't (ever).
Have you ever experienced any problem similar to this one using iText library?
Is the problem at the PDF files that make the code crash and not in my project?
I'm completely stuck here so any help/tip would be appreciated. Thanks in advance.