Am 12.07.2015 um 09:29 schrieb Roberto Nibali:
Hi


On Sat, Jul 11, 2015 at 7:48 AM, Tilman Hausherr <[email protected]>
wrote:

I just tested myself and ...????!!!!!

But I found the solution:

call
tplDoc.setAllSecurityToBeRemoved(false);

before saving

and it works for me.

(Maybe we should warn about that when calling protec()   )


Thanks for the hint. It did indeed solve one issue, namely that now the
password is set. However, the security settings are still not as depicted
in the referenced example files. What's wrong with this approach?

@Test
public static void SimpleTest() throws IOException {
     String dir = "./";
     String ownerPassword = "veryimportantsecret";
     String userPassword = "";
     int encKeyLen;

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

     do_something_with_the_pdfs();

     AccessPermission srcDocAP = srcDoc.getCurrentAccessPermission();
     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);
     encKeyLen = srcDoc.getEncryption().getLength();
     policy.setEncryptionKeyLength(encKeyLen);

     srcDoc.close();
     tplDoc.setAllSecurityToBeRemoved(false); //Hint from Tilmann
     tplDoc.protect(policy);
     tplDoc.save("ccmig.pdf");
     tplDoc.close();
}

Basically, I would like to copy the previously existing security settings
to the new template PDF and subsequently to the output PDF. The hint allows
me to at least get the password back into the PDF.

Your code is correct (so it seems).

If when opening the file with Adobe Reader it does display "GESCHÜTZT" in the title bar, then at least "something" has been done.

The difference should be seen by showing the doc properties.

Possible idea: the version of the PDF. Maybe get the version of the old PDF and assign it to the new one.

Possible

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to