pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roberto Nibali <rnib...@gmail.com>
Subject Re: Setting document restrictions and security
Date Sun, 12 Jul 2015 07:29:03 GMT
Hi


On Sat, Jul 11, 2015 at 7:48 AM, Tilman Hausherr <THausherr@t-online.de>
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.

Why isn't the API providing alteration of all security settings?

Best regards
Roberto

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