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)
[ ]'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]
--
_______________________________________________
<logo-e-sec2.png>Diego Azevedo
Desenvolvedor
E-SEC Segurança Digital
www.esec.com.br
61 3323-4410
Os dados transmitidos, incluindo quaisquer anexos, são destinados apenas para a
pessoa ou entidade ao qual está endereçada e pode conter material confidencial
e/ou privilegiado. É proibida qualquer revisão, retransmissão, disseminação ou
outro uso desta informação, ou a tomada de qualquer ação com base na confiança,
por pessoas ou empresas que não o destinatário, e qualquer responsabilidade daí
decorrente é negada. Se você recebeu por engano, favor contatar o remetente e
apague o material de qualquer computador
The information transmitted, including any attachments, is intended only for
the person or entity to which it is addressed and may contain confidential
and/or privileged material. Any review, retransmission, dissemination or other
use of, or taking of any action in reliance upon, this information by persons
or entities other than the intended recipient is prohibited, and all liability
arising therefrom is disclaimed. If you received this in error, please contact
the sender and delete the material from any computer
---------------------------------------------------------------------
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]