我正在使用此sample PDFBox code来加密和禁用pdf文件的打印。加密成功,但不禁用打印。
可能是什么问题?
这是我的pom.xml的依赖项部分
<dependencies>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15</artifactId>
<version>1.46</version>
</dependency>
</dependencies>
以下是源代码
import java.io.File;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy;
public class Test {
public static void main(String[] args) throws Exception {
PDDocument doc = PDDocument.load(new File("/tmp/Test.pdf"));
int keyLength = 128;
AccessPermission ap = new AccessPermission();
ap.setCanPrint(false);
StandardProtectionPolicy spp = new StandardProtectionPolicy("Admin", "Password", ap);
spp.setEncryptionKeyLength(keyLength);
spp.setPermissions(ap);
doc.protect(spp);
doc.save("/tmp/Test-Encrypted.pdf");
doc.close();
}
}