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

Maruan Sahyoun commented on PDFBOX-3396:
----------------------------------------

I've also looked at above code which can be shortened to

{code}
PDDocument pdDoc = PDDocument.load("signed-document.pdf");
PDDocumentCatalog pdCatalog = pdDoc.getDocumentCatalog();
PDAcroForm acroForm = pdCatalog.getAcroForm();
acroForm.flatten();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pdDoc.save(baos);
{code}

specifically the following lines are not ideal
{code}
pfs.getAcroForm().flatten();
pfs.getAcroForm().refreshAppearances();
{code}

# after the first {{pfs.getAcroForm().flatten()}} there are no more fields and 
as a result subsequent calls do not make any sense
# {{pfs.getAcroForm().refreshAppearances()}} should be done prior to 
{{flatten()}} if you want to make sure that all appearances were properly 
generated by PDFBox (which you don't need to do at all if the form filling 
application already took care of). Calling it after {{flatten()}} wouldn't have 
any effect as there are no more fields.

Please also note that appearance generation is always specific by the filling 
application as the details of the look & feel are not part of the PDF 
specification. In addition PDFBox support for appearance generation of 
signature fields.

If you would only like to flatten specific fields use 
{{PDAcroForm.flatten(List<PDField> boolean refreshAppearances)}} instead.


> flattaning AcroForm with visible sign field ETSI.CAdES.detached
> ---------------------------------------------------------------
>
>                 Key: PDFBOX-3396
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3396
>             Project: PDFBox
>          Issue Type: Bug
>          Components: AcroForm
>    Affects Versions: 2.0.1, 2.0.2
>         Environment: Java 8 - Spring Boot
>            Reporter: Fabio
>            Priority: Critical
>             Fix For: 2.0.3, 2.1.0
>
>         Attachments: Signed-Document-1.pdf, Signed-Document-2.pdf, 
> Signed-Document-Flattened-1.pdf, Signed-Document-Flattened-2.pdf, 
> Signed-Document-Flattened.pdf, Signed-Document.pdf
>
>
> Hallo,
> I've got a problem with the flattaning function of AcroForm class of a 
> PDSignatureField. I've a signed pdf document with ETSI.CAdES.detached visible 
> image at bottom of the file. I want to flattan the PDSignatureField of the 
> sign to eliminate sign cryptography element of the field and to embad the 
> sign marker immage of the sign, in the same position of the original immage 
> that is a part of the marker sign ETSI.CAdES.detached. I try this way(pseudo 
> code similare to real code):
> {code}
> PDDocument pdDoc = PDDocument.load("signed-document.pdf");
> PDDocumentCatalog pdCatalog = pdDoc.getDocumentCatalog();
> PDAcroForm acroForm = pdCatalog.getAcroForm();
> List<PDField> fields = acroForm.getFields();
> fields.stream().filter(pf -> 
> pf.getFieldType().toLowerCase().contains("sig")).forEach(pf -> {
> try {
>       PDSignatureField pfs = ((PDSignatureField)(pf));
>       
>        log.info("START remove Sign Flags");
>        pfs.setReadOnly(true);
>        pfs.setRequired(false);
>        pfs.setNoExport(true);
>        log.info("END remove Sign Flags");
>        
>        log.info("START flatten field");
>        pfs.getAcroForm().flatten();
>        pfs.getAcroForm().refreshAppearances();
>        log.info("END flatten field");
>                                       
> } catch (Exception ex) {
>    log.error("flattenFile --> Error: " + ex.getMessage());
>    throw new RuntimeException(ex);
> }
> });
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> pdDoc.save(baos);
> .
> .
> .
> {code}                
> At the and of the process, the pdf file in output, has no sign cryptography 
> element, but the visible marker immage of the sign is placed in a wrong 
> position, on top of sign above paragraph of the document and not in original 
> position of the signed marker immage. That's happen when i call the following 
> method:
> {code}
>        pfs.getAcroForm().flatten();
> {code}
> In other words, the flattened pdf of the original signed pdf, has in a 
> correct way no more sign inside but, the immage of the ETSI.CAdES.detached 
> signe is embedded in a wrong position, over the text of the nearest above 
> paragraph of the pdf document.
> My questions are: 
> 1-My way, is the correct way to flattan a signed ETSI.CAdES.detached file?
> 2-Is there a method to remove CadES/PadES sign with a official visible marker 
> image and, embad immage in the acctual original position in pdf file?
> Thank you for your support and sorry for my poor English.
> Best regards,
> Fabio Evangelista



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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to