Daddy Pumpkin
Daddy Pumpkin

Reputation: 484

PDFBox 2.0.0 - decryption using password

I'm trying to unlock a PDF using a password with PDFBox 2.0.0.

In 1.8.11 I was using the PDDocument.openProtection(DecryptionMaterial pm) method but it was removed in 2.0.0 from what I see.

The online documentation does not say how this can be achived in 2.0.0.

Question:

The PDF unlocking with password is still possible in PDFBox 2.0.0?

Upvotes: 5

Views: 4086

Answers (2)

Sujoy
Sujoy

Reputation: 822

I used the latest version with the following code:

  PDDocument pd = PDDocument.load(ResourceUtils.getFile("[Your_File_Path]"), "[Your_Password]");
  pd.setAllSecurityToBeRemoved(true);
  pd.save("[New_FileName.pdf]");

pom.xml

<dependency>
        <groupId>org.apache.pdfbox</groupId>
        <artifactId>pdfbox</artifactId>
        <version>2.0.22</version>
    </dependency>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk15on</artifactId>
        <version>1.68</version>
    </dependency>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcmail-jdk15on</artifactId>
        <version>1.68</version>
    </dependency>

Upvotes: 2

Tilman Hausherr
Tilman Hausherr

Reputation: 18851

In 2.0, you just call PDDocument.load(file, password) or PDDocument.load(file) (if the password is empty). You don't have to call openProtection() anymore. The load() of 2.0 call is similar to the loadNonSeq() call of 1.8.

Upvotes: 12

Related Questions