1

I want to download and convert pdf files into plain text by using itextpdf.5.4.1. For most of them my code works but for one of them I encountered the error below when I try to read the file.

PdfReader reader = new PdfReader(pdf_file_path);


Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Primitive

Does it mean that this pdf is protected and there is no way to extract the text?

mlee_jordan
  • 772
  • 4
  • 18
  • 50
  • 1
    possible duplicate of [iText and org.bouncycastle.asn1.ASN1Primitive not found](http://stackoverflow.com/questions/14042693/itext-and-org-bouncycastle-asn1-asn1primitive-not-found) – mkl Nov 18 '14 at 10:28
  • And are you sure you mean [javascript], not [java]? – mkl Nov 18 '14 at 10:30
  • thanx @mkl. I editted it. – mlee_jordan Nov 18 '14 at 10:36
  • please put the appropriate version of bouncycastle in your classpath – Michaël Demey Nov 18 '14 at 10:39
  • @mkl I have just added extra.jars 2.3 and put the jar file "Bcprov-jdk15on-1.48.jar". But this time i got the following error. 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 – mlee_jordan Nov 18 '14 at 10:51
  • 2
    *does not match signer information of other classes in the same package* - check whether you have multiple bc versions on your class path. That error might be caused by a mixture of different versions. – mkl Nov 18 '14 at 11:04
  • thank you @mkl. I've noticed that I have also pdfbox jar files in the package which cause the error. When removing them problem has been solved. – mlee_jordan Nov 18 '14 at 11:21

2 Answers2

5

I was also facing the same problem while reading pdf uing itext 5.5.10.

I changed the dependancies to following :

    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itextpdf</artifactId>
        <version>5.5.4</version>
    </dependency>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk15on</artifactId>
        <version>1.49</version>
    </dependency>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcpkix-jdk15on</artifactId>
        <version>1.49</version>
    </dependency>

You can also refer : https://stackoverflow.com/a/27575336/3150912

Community
  • 1
  • 1
0

That's cause of different versions of itext in your project. Please, check out your dependencies in your build file.

Alex Gorbunov
  • 239
  • 3
  • 8
  • If you read the comments to the question, you'd know that it is *not* about different iText versions but instead at first the wrong and later different BouncyCastle versions. – mkl May 05 '15 at 11:45
  • bouncycasle lib definitely contain above class, but usually it is not being used explicitly. What am I saying is that perhaps this is about dependency from Itext (com.itextpdf or com.lowagie.itext) libs – Alex Gorbunov May 06 '15 at 12:39
  • 1
    and one more thing: target lib could be marked as optional in parent pom.xml (if you'r' using Maven), so sometimes you have to add lib like org.bouncycastle (bcprov) in explicit way into your project. – Alex Gorbunov May 06 '15 at 12:41