简体   繁体   中英

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?

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM