[ 
https://issues.apache.org/jira/browse/PDFBOX-2729?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15067014#comment-15067014
 ] 

Gladkovsky Gleb edited comment on PDFBOX-2729 at 12/22/15 10:01 AM:
--------------------------------------------------------------------

I've managed to create a visible signature on protected file. My initial goal 
is to protect file and sign it at one time, but it works for protected files 
too. My problem that I cannot sign document twice, without damaging first 
signature. 
I've attached my pdfs
Password is 111
Document content is irrelevant to the topic 

Here is my snippets
When you load your pdf file, check if it is protected, load it with Owner 
password and reset all security.

         ...
        this.document = PDDocument.load(pdf, ownerPassword);
        document.setAllSecurityToBeRemoved(true);
        ...
To make document protected again you should create new StandartProtectionPolicy 
with old passwords and premissions, save document, and then load it with 
password, sign it and save it again.

    .....
    StandardProtectionPolicy policy = new 
StandertProtectionPolicy(ownerPassword, userPassword, accessPremission)
       doc.protect(policy);
       doc.save(signedFile);
       doc.close();
       doc = PDDocument.load(signedFile, policy.getOwnerPassword());
       doc.protect(policy);
       ....
       doc.addSignature(signature, this, options);
This works for me.
http://stackoverflow.com/questions/29232684/signing-an-encrypted-pdf-document-with-pdfbox-2-0-0/34403363#34403363



was (Author: gglad):
I've managed to create a visible signature on protected file. My initial goal 
is to protect file and sign it at one time, but it works for protected files 
too. My problem that I cannot sign problem document twice, without damaging 
first signature. 
I've attached my pdfs
Password is 111
Document content is irrelevant to the topic 

Here is my snippets
When you load your pdf file, check if it is protected, load it with Owner 
password and reset all security.

         ...
        this.document = PDDocument.load(pdf, ownerPassword);
        document.setAllSecurityToBeRemoved(true);
        ...
To make document protected again you should create new StandartProtectionPolicy 
with old passwords and premissions, save document, and then load it with 
password, sign it and save it again.

    .....
    StandardProtectionPolicy policy = new 
StandertProtectionPolicy(ownerPassword, userPassword, accessPremission)
       doc.protect(policy);
       doc.save(signedFile);
       doc.close();
       doc = PDDocument.load(signedFile, policy.getOwnerPassword());
       doc.protect(policy);
       ....
       doc.addSignature(signature, this, options);
This works for me.
http://stackoverflow.com/questions/29232684/signing-an-encrypted-pdf-document-with-pdfbox-2-0-0/34403363#34403363


> Can't sign encrypted PDF files
> ------------------------------
>
>                 Key: PDFBOX-2729
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2729
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Signing
>    Affects Versions: 2.0.0
>            Reporter: Cyril Bremaud
>            Assignee: Andreas Lehmkühler
>         Attachments: Scan0001.pdf, Scan0001_protected.pdf, 
> Scan0001_protected_signed.pdf
>
>
> It is not possible to sign an encrypted PDF document.
> More details here :
> [http://stackoverflow.com/questions/29232684/signing-an-encrypted-pdf-document-with-pdfbox-2-0-0]



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to