PDFBox 2.0.0 - 使用密码解密
PDFBox 2.0.0 - decryption using password
我正在尝试使用 PDFBox 2.0.0 的密码解锁 PDF。
在 1.8.11 中,我使用的是我所看到的 PDDocument.openProtection(DecryptionMaterial pm) method but it was removed in 2.0.0。
online documentation 没有说明如何在 2.0.0 中实现。
问题:
PDFBox 2.0.0还可以用密码解锁PDF吗?
在 2.0 中,您只需调用 PDDocument.load(file, password)
或 PDDocument.load(file)
(如果密码为空)。您不必再调用 openProtection()
。 2.0的load()
调用类似于1.8的loadNonSeq()
调用。
我使用的是最新版本,代码如下:
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>
我正在尝试使用 PDFBox 2.0.0 的密码解锁 PDF。
在 1.8.11 中,我使用的是我所看到的 PDDocument.openProtection(DecryptionMaterial pm) method but it was removed in 2.0.0。
online documentation 没有说明如何在 2.0.0 中实现。
问题:
PDFBox 2.0.0还可以用密码解锁PDF吗?
在 2.0 中,您只需调用 PDDocument.load(file, password)
或 PDDocument.load(file)
(如果密码为空)。您不必再调用 openProtection()
。 2.0的load()
调用类似于1.8的loadNonSeq()
调用。
我使用的是最新版本,代码如下:
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>