[
https://issues.apache.org/jira/browse/PDFBOX-3699?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15888525#comment-15888525
]
Tilman Hausherr commented on PDFBOX-3699:
-----------------------------------------
What would you prefer - to put this in the examples, or to put this into
PDDocument.addSignature() ?
This code should gets the permission; for a new visual signature, only 3 or 0
would be acceptable.
{code}
/**
* Get the access permissions granted for this document in the DocMDP
transform parameters
* dictionary. Details are described in the table "Entries in the DocMDP
transform parameters
* dictionary" in the PDF specification.
*
* @param doc document.
* @return the permission value. 0 means no DocMDP transform parameters
dictionary exists. Other
* return values are 1, 2 or 3. 2 is also returned if the DocMDP transform
parameters dictionary
* is found but did not contain a /P entry, or if the value is outside the
valid range.
*/
private int getMDPPermission(PDDocument doc)
{
COSBase base =
doc.getDocumentCatalog().getCOSObject().getDictionaryObject(COSName.PERMS);
if (base instanceof COSDictionary)
{
COSDictionary permsDict = (COSDictionary) base;
base = permsDict.getDictionaryObject(COSName.DOCMDP);
if (base instanceof COSDictionary)
{
COSDictionary signatureDict = (COSDictionary) base;
base = signatureDict.getDictionaryObject("Reference");
if (base instanceof COSArray)
{
COSArray refArray = (COSArray) base;
for (int i = 0; i < refArray.size(); ++i)
{
base = refArray.getObject(i);
if (base instanceof COSDictionary)
{
COSDictionary sigRefDict = (COSDictionary) base;
if
("DocMDP".equals(sigRefDict.getNameAsString("TransformMethod")))
{
base =
sigRefDict.getDictionaryObject("TransformParams");
if (base instanceof COSDictionary)
{
COSDictionary transformDict =
(COSDictionary) base;
int accessPermissions =
transformDict.getInt(COSName.P, 2);
if (accessPermissions < 1 ||
accessPermissions > 3)
{
accessPermissions = 2;
}
return accessPermissions;
}
}
}
}
}
}
}
return 0;
}
{code}
> Regression on signature with certification flag.
> ------------------------------------------------
>
> Key: PDFBOX-3699
> URL: https://issues.apache.org/jira/browse/PDFBOX-3699
> Project: PDFBox
> Issue Type: Bug
> Components: Signing
> Affects Versions: 2.0.2, 2.0.3, 2.0.4
> Reporter: Marco Monacelli
> Priority: Blocker
> Attachments: original_file.pdf,
> signed_2.0.0_ok_previus_signature_but_invisible.pdf,
> signed_2.0.4_previus_signature_ko_but_signature_visible.pdf,
> TEST_PDFBOX_signed_module_acrobat_final_signature.pdf,
> TEST_PDFBOX_signed_module_acrobat.pdf
>
>
> Hello,
> I got some problems signing a certified pdf with a signature with apparence:
> after the signature is applied the previous certification is reported as
> corrupted by Acrobat Reader. If I apply an invisible signature the issue
> doesn't happen.
> I have done a regression analysis using the same code
> - with pdfbox 2.0.0 and 2.0.1, the signature is not shown on the document but
> the certification is still valid
> - with earlier versions, the signature is shown on the document but the
> certification is broken
> The sample certified pdf (original_file.pdf) is in attachment.
> Finally this problem could be related to these tickets:
> 1- https://issues.apache.org/jira/browse/PDFBOX-2816 (PDFBox makes disallowed
> changes when signing a signed document)
> 2- https://issues.apache.org/jira/browse/PDFBOX-45 (Support incremental save)
> I tested my code with the test case file in 1 (acrosigned.pdf), and it works
> well.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]