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

Tilman Hausherr commented on PDFBOX-4556:
-----------------------------------------

I assume you meant to write "but its noT working with the pdfbox 1.8". I also 
assume that with "all needed objects can not read from the template" you meant 
the message "Could not read all needed objects from template" (always use copy 
& paste for error messages, because I use these to search in the source code so 
having the exact spelling is important). That one comes if the template either 
doesn't have the annotation or doesn't have the signature field in the acroform.

The template is passed with 
{{options.setVisualSignature(signatureProperties)}}. In {{signatureProperties}} 
there is an {{inputStream}} that is a PDF. This {{inputStream}} is a 
{{ByteArrayInputStream}} so you can (and should) reset it after saving it for 
inspection, so that the {{inputStream}} is still usable.

The actual show happens in {{PDFTemplateCreator.buildPDF()}}, which is called 
by {{PDVisibleSigProperties.buildSignature()}}, which is called by the example.

So to save your visible signature template into a file, here's what to do, add 
these 5 lines in the sample code at the described place:
{code:java}
signatureProperties.signerName("name").signerLocation("location").signatureReason("Security").preferredSize(0)
   
.page(page).visualSignEnabled(true).setPdVisibleSignature(visibleSig).buildSignature();
 // existing example code

ByteArrayInputStream visibleSignature = (ByteArrayInputStream) 
signatureProperties.getVisibleSignature();
FileOutputStream fos = new FileOutputStream(new 
File("......\\visibleSignature.pdf"));
IOUtils.copy(visibleSignature, fos);
fos.close();
visibleSignature.reset();

signing.signPDF(document, signatureProperties); // existing example code
{code}
When you have the file, inspect it with PDFDebugger, look whether it has the 
signature image, the annotation, and the acroform field. Or attach the file to 
this issue. The example hasn't been modified for 3 years and I just checked 
that it still works fine.

PDVisibleSigProperties and all these design pattern modeled classes 
(PDVisibleSigProperties, PDFTemplateCreator, and many more) are difficult to 
use. Instead of using them, you could also create your template PDF and then 
pass it as an inputStream in {{options.setVisualSignature(inputStream)}}, that 
is what {{CreateVisibleSignature2}} is doing. But first you should get the 
unmodified example to work.

> how the visual representation of the signature is achieved  
> ------------------------------------------------------------
>
>                 Key: PDFBOX-4556
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4556
>             Project: PDFBox
>          Issue Type: Wish
>          Components: .NET
>    Affects Versions: 1.8.16
>            Reporter: bal
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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

Reply via email to