pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roberto Nibali <rnib...@gmail.com>
Subject Setting document restrictions and security
Date Fri, 10 Jul 2015 21:50:31 GMT
Hello

In my quest to migrate forms from one pdf to a new one, I just realized
that the resulting PDF does not have the same document restrictions and
document security settings anymore. The original PDF has the following
entries:
​​
https://drive.google.com/file/d/0B7Bzk_1dcyc5UDd5c2FUSVRXRmc/view?usp=sharing

The newly created PDF using PDFBox has the following reduced settings for
both the document restrictions and the document security:

https://drive.google.com/file/d/0B7Bzk_1dcyc5cU8tYTFvVDNXREk/view?usp=sharing

This is how I have tried to remedy the situation, but nothing changes:

String dir = "./";
String ownerPassword = "";
String userPassword = "hidden";
PDDocument srcDoc;
PDDocument tplDoc;

srcDoc = PDDocument.load(new File(dir, "ccalt.pdf"), userPassword);
tplDoc = PDDocument.load(new File(dir, "cctemp.pdf"), userPassword);
tplDoc.setAllSecurityToBeRemoved(true);

AccessPermission srcDocAP = srcDoc.getCurrentAccessPermission();
System.out.println("RO/OP:" + srcDocAP.isReadOnly() + "/" +
srcDocAP.isOwnerPermission());

AccessPermission destDocAP = new AccessPermission();
destDocAP.setCanAssembleDocument(srcDocAP.canAssembleDocument());
destDocAP.setCanExtractContent(srcDocAP.canExtractContent());
destDocAP.setCanExtractForAccessibility(srcDocAP.canExtractForAccessibility());
destDocAP.setCanFillInForm(srcDocAP.canFillInForm());
destDocAP.setCanModify(srcDocAP.canModify());
destDocAP.setCanModifyAnnotations(srcDocAP.canModifyAnnotations());
destDocAP.setCanPrint(srcDocAP.canPrint());
destDocAP.setCanPrintDegraded(srcDocAP.canPrintDegraded());

StandardProtectionPolicy policy = new
StandardProtectionPolicy(ownerPassword, userPassword, destDocAP);
//policy.setPermissions(srcDocAP);

srcDoc.close();
tplDoc.protect(policy);
tplDoc.save("ccmig.pdf");
tplDoc.close();

What am I doing wrong now? The output of the println statement is:
RO/OP:false/true

Best regards
Roberto

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message