How to open password protected pdf using itext

11,694

Solution 1

Starting from iText 2.0.0 you need the BouncyCastle jars. You need to download it from its site. More info can be found from here:

java.lang.NoClassDefFoundError

Solution 2

try {
   PdfReader pdfReader = new PdfReader(String.valueOf(file));
   pdfReader.isEncrypted();
} catch(IOException) {
   e.printStackTrace();
}
Share:
11,694
RAVITEJA SATYAVADA
Author by

RAVITEJA SATYAVADA

Updated on June 04, 2022

Comments

  • RAVITEJA SATYAVADA
    RAVITEJA SATYAVADA almost 2 years

    I am using iText library to read PDF files. It's working fine for all the pdf files, except for password protected ones. I used some way by using the overloading constructor of PdfReader class

    PdfReader reader = new PdfReader("locked pdf file","password".getBytes());
    

    But it is showing show error like :

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

    Is there any other to read password protected pdf file? or should I include bouncy castle into my project library?