Thanks!
Thank you Tilman, I'm gonna run both files on PDFDebuger to try to
understand more, and I'll come back if I need anything.
Thank you Maruan, I'll also read your links to clear things up. You said
something about a new approach on version 2.1, is this release coming soon?
[ ]'s
Diego Azevedo
On 30/07/2016 08:24, Tilman Hausherr wrote:
Am 29.07.2016 um 23:20 schrieb Diego Azevedo:
Uhm.... Good idea.
The appearance should be the /N entry inside the /AP entry on the /FT
/Sig dictionary, right? (I'm no PDF expert, it just kind of made
sense (maybe?))
This PDF here has the appearance I want (sent by my client):
https://drive.google.com/open?id=0B9u-J6HILTH6NE1SSVVDZHhWSmc
I tried to find it's appearance dictionary:
11 0 obj
<</F 132/Type/Annot/Subtype/Widget/Rect[5 5 240
120]/FT/Sig/DR<</XObject<</FRM 9 0 R>>>>/T(Signature1)/V 1 0 R/P 12 0
R/AP<</N 10 0 R>>>>
endobj
10 0 obj
<</Type/XObject/Resources<</XObject<</FRM 9 0 R>>/ProcSet [/PDF /Text
/ImageB /ImageC /ImageI]>>/Subtype/Form/BBox[0 0 235 115]/Matrix [1 0
0 1 0 0]/Length 29/FormType 1/Filter/FlateDecode>>stream
q 1 0 0 1 0 0 cm /FRM Do Q
endstream
endobj
Are these the droids I'm looking for? (I have absolutely no idea what
this means)
What you're looking for in the IBM file is here (in PDFDebugger):
Root/Pages/Kids/[0]/Kids/[0]/Annots/[0]/AP/N/Resources/XObject/FRM/Resources/XObject/n2
You'll see this:
q
235 0 0 115 0 0 cm
/img0 Do
Q
BT
1 0 0 1 2 66.5 Tm
/F1 12 Tf
(Digitally signed by a) Tj
1 0 0 1 2 54.5 Tm
(Date: 2015.09.02 15:36:40 BRT) Tj
1 0 0 1 2 42.5 Tm
(Reason: Valida\347\343o de Documento) Tj
1 0 0 1 2 30.5 Tm
(Location: Rio de Janeiro) Tj
ET
So it is in the n2 layer. The layers n1, n3, n4 should not be used
anymore.
The /FRM stream (at
Root/Pages/Kids/[0]/Kids/[0]/Annots/[0]/AP/N/Resources/XObject/FRM )
looks like this:
q
1 0 0 1 0 0 cm
/n0 Do
Q
q
1.03 0 0 1.03 65.75 5.75 cm
/n1 Do
Q
q
1 0 0 1 0 0 cm
/n2 Do
Q
q
1.03 0 0 1.03 65.75 5.75 cm
/n3 Do
Q
q
1 0 0 1 0 0 cm
/n4 Do
Q
It should be this:
q
1 0 0 1 0 0 cm
/n0 Do
Q
q
1 0 0 1 0 0 cm
/n2 Do
Q
About your problem file:
1) should be n2 instead of n1
2) this is wrong:
q
100 0 0 50 0 0 cm
/COSName{img1} Do
Q
BT
/F1 6 Tf
(Hello) Tj
ET
It should be /img1 not "/COSName{img1}" (use .getName() instead of
toString()), and besides, the image belongs to the n0 layer.
Tilman
[ ]'s
Diego Azevedo
On 29/07/2016 16:44, Maruan Sahyoun wrote:
Hi,
Am 29.07.2016 um 19:39 schrieb Diego Azevedo <[email protected]>:
Thanks Tilman,
Well, here is the source code (only the visual signature bit):
// Creates the designer and set properties
PDVisibleSignDesigner sigDesigner = new PDVisibleSignDesigner(doc,
image, page);
sigDesigner.xAxis(100).yAxis(200).zoom(-50);
PDVisibleSigProperties visibleSigProp = new PDVisibleSigProperties();
visibleSigProp.setPdVisibleSignature(sigDesigner).signatureReason("Test");
// this should replace visibleSigProp.buildSignature()
PDFTemplateBuilder builder = new ExtSigBuilder();
PDFTemplateCreator creator = new PDFTemplateCreator(builder);
visibleSigProp.setVisibleSignature(creator.buildPDF(visibleSigProp.getPdVisibleSignature()));
// add VisibleSignature options to general signature options
SignatureOptions sigOpts = new SignatureOptions();
sigOpts.setVisualSignature(visibleSigProp);
sigOpts.setPage(0);
// add signature options to signature
doc.addSignature(sigDic, mySigner, sigOpts );
The class used to modify the behavior was:
// Test -> should write "Hello" on the top-left corner (adapted
from stackoverflow - String to COSName)
public class ExtSigBuilder extends PDVisibleSigBuilder
{
String fontName;
@Override
public void createImageForm(PDResources
imageFormResources, PDResources innerFormResource,
PDStream imageFormStream, PDRectangle formrect,
AffineTransform affineTransform, PDImageXObject img)
throws IOException
{
super.createImageForm(imageFormResources,
innerFormResource, imageFormStream, formrect, affineTransform, img);
PDFont font = PDType1Font.HELVETICA;
fontName =
getStructure().getImageForm().getResources().add(font).getName();
}
@Override
public void injectAppearanceStreams(PDStream
holderFormStream, PDStream innterFormStream, PDStream imageFormStream,
COSName imageObjectName, COSName imageName,
COSName innerFormName, PDVisibleSignDesigner properties)
throws IOException
{
super.injectAppearanceStreams(holderFormStream,
innterFormStream, imageFormStream, imageObjectName, imageName,
innerFormName, properties);
String imgFormComment = "q " + 100 + " 0 0 50 0 0 cm
/" + imageName + " Do Q\n";
String text = "BT /" + fontName + " 6 Tf (Hello) Tj
ET\n";
appendRawCommands(getStructure().getImageFormStream().createOutputStream(),
imgFormComment + text);
}
}
When I don't use ExtSigBuilder or comment the 'appendRawCommands',
I get this: link
But when I try to add this visible layer, the retangle becomes
blank: link
You said that there is no example, but can I achieve it if I'm
willing to get dirty and use low level API's? Is there a
recommended architecture I can follow to merge this on the project
latter?
it's possible. One way to approach it is to create a visible
signature with the text in Adobe Acrobat and inspect and replicate
the sppearance stream.
BR
Maruan
Thanks in advance,
Diego Azevedo
On 29/07/2016 13:54, Tilman Hausherr wrote:
Am 29.07.2016 um 15:36 schrieb Diego Azevedo:
Hello all,
I'm trying to add a visible signature to a pdf document -> So
far, no problems
But I've seen documents that add a text layer above the visible
signature that shows some of the signature details, such as
location, reason, date, the validity of the signature (and that's
updated if, for example, you trust a root certificate). I'd like
to add these features, but I didn't find any example on the SVN
directory.
The closest I got was this stackoverflow question
<http://stackoverflow.com/questions/27926407/visual-signature-with-pdfbox-1-8-8>,
but that did not work for me (I changed the methods signatures to
the updated API, but all I got was a blank rectangle).
The text layer isn't supported, or rather, there is no example for
it.
What you could do is to post your source code and upload the
result PDF somewhere, I'll see if I can find something.
Btw a known problem is signing rotated pages (there's an SO issue
about that too), so make sure your page isn't.
Tilman
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]