Hi,
I was trying to use the "setCanPrintDegraded" method of the
"org.apache.pdfbox.pdmodel.encryption.AccessPermission"
It appears that printing permission could not be changed in any way by this
API. Only the ap.setCanPrint(true) API works.
I also saw that the argument name in the "setCanPrintDegraded" method is
incorrect (Copy-pase error!!).
Could someone help me to understand if this feature works or not ? And what
code changes needs to be done?
RegardsIndrajit
Here is the code :___________________________package com.pdf.test.encrypter;
import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy;
public class Encrypter {
public static void main(String[] args) {
// TODO Auto-generated method stub
PDDocument doc = null;
try {
doc = PDDocument.load(new
File("E:\\...dolil\\pdf\\...-unsecured.pdf"));
} catch (InvalidPasswordException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Define the length of the encryption key.
// Possible values are 40 or 128 (256 will be available in PDFBox 2.0).
int keyLength = 128;
AccessPermission ap = new AccessPermission();
// disable printing, everything else is allowed
ap.setCanPrint(true);
ap.setCanPrintDegraded(true);
ap.setCanAssembleDocument(false);
ap.setCanExtractContent(false);
ap.setCanFillInForm(false);
ap.setCanExtractForAccessibility(false);
ap.setCanModify(false);
ap.setCanModifyAnnotations(false);
// owner password (to open the file with all permissions) is "12345"
// user password (to open the file but with restricted permissions, is
empty here)
StandardProtectionPolicy spp = new StandardProtectionPolicy("12345",
"67890", ap);
spp.setEncryptionKeyLength(keyLength);
spp.setPermissions(ap);
try {
doc.protect(spp);
doc.save("E:\\..dolil\\pdf\\....pdf");
doc.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}____________________________________