Am 16.01.2017 um 08:49 schrieb Indrajit Kanjilal:
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
Thanks for the hint re: javadoc. I've fixed it.
I looked at the PDF specification:
"Print the document to a representation from which a faithful digital
copy of the PDF content could be generated. When this bit is clear (and
bit 3 is set), printing is limited to a low-level representation of the
appearance, possibly of degraded quality."
So this means it must be set to false to print degraded. Could you
please test this with your file, and give feedback? I would then either
change the code or clarify this in the javadoc.
Tilman
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();
}
}____________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]