Hi,

> Am 27.07.2015 um 14:45 schrieb Roberto Nibali <[email protected]>:
> 
> Hello
> 
> I've managed to somehow hardcode the security settings:
> 
> On Mon, Jul 27, 2015 at 2:23 PM, Roberto Nibali <[email protected]> wrote:
> 
>> Hi
>> 
>> I'm trying to replicate the document security settings using PDFBox and
>> can't seem to get it working at all. This is the code I use:
>> 
>> private static PDDocument srcDoc;
>> private static PDDocument tplDoc;
>> 
>> @Test
>> public static void SimpleTest() throws IOException {
>>    String ownerPassword = "12345";
>>    srcDoc = PDDocument.load(new File("./ccalt.pdf"), ownerPassword);
>>    tplDoc = PDDocument.load(new File("./cctemp.pdf"), ownerPassword);
>>    tplDoc.setAllSecurityToBeRemoved(true);
>>    applyDocPermissions(ownerPassword, "");
>>    srcDoc.close();
>>    tplDoc.getDocumentCatalog().getAcroForm().setNeedAppearances(true);
>>    tplDoc.save("ccmig.pdf");
>>    tplDoc.close();
>> }
>> public static void applyDocPermissions(String ownerPassword, String 
>> userPassword) throws IOException {
>>    int encKeyLen;
>>    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);
>>    tplDoc.setAllSecurityToBeRemoved(false);
>>    tplDoc.protect(policy);
>> }
>> 
>> 
> Using the following function, it works:
> 
> public static void applyDocPermissionsHardcoded(String ownerPassword,
> String userPassword) throws IOException {
>    int encKeyLen;
> 
>    AccessPermission srcDocAP = srcDoc.getCurrentAccessPermission();
>    AccessPermission destDocAP = new AccessPermission();
>    destDocAP.setCanPrint(true);
>    //destDocAP.setCanPrintDegraded(false);
>    destDocAP.setCanModify(false);
>    destDocAP.setCanAssembleDocument(false);
>    destDocAP.setCanExtractContent(false);
>    destDocAP.setCanExtractForAccessibility(true);
>    //Page Extraction = false
>    destDocAP.setCanModifyAnnotations(false);
>    destDocAP.setCanFillInForm(true);
>    //Signing = true
>    //Creation of Template Pages = true
>    StandardProtectionPolicy policy = new
> StandardProtectionPolicy(ownerPassword, userPassword, destDocAP);
>    encKeyLen = srcDoc.getEncryption().getLength();
>    policy.setEncryptionKeyLength(encKeyLen);
>    tplDoc.setAllSecurityToBeRemoved(false);
>    tplDoc.protect(policy);
> }
> 

can you try


        StandardProtectionPolicy policy = new 
StandardProtectionPolicy(ownerPassword, userPassword, null);
        int encKeyLen = srcDoc.getEncryption().getLength();
        policy.setEncryptionKeyLength(encKeyLen);
        policy.setPermissions(srcDocAP);


Please verify the settings in the details view of the Acrobat security tab.

BR
Maruan



> Let's hope all documents I need to migrate have the same security settings.
> For now, this issue does not need to be looked at anymore. What's
> funny is that using PDFBox, I cannot modify the
> page extraction, signing or the creation of template pages bits in
> the security settings. Is this missing in the implementation?
> 
> Cheers
> 
> Roberto


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

Reply via email to