You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Diego Azevedo <da...@esec.com.br> on 2016/07/29 13:36:06 UTC

Visible Signature with text

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).

Thanks in advance,

Diego Azevedo

Re: Visible Signature with text

Posted by Diego Azevedo <da...@esec.com.br>.
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 <da...@esec.com.br>:
>>>>
>>>> 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: users-unsubscribe@pdfbox.apache.org
>>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Visible Signature with text

Posted by Tilman Hausherr <TH...@t-online.de>.
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 <da...@esec.com.br>:
>>>
>>> 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: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>
>>> -- 
>>> _______________________________________________
>>>
>>> <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: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Visible Signature with text

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 30.07.2016 um 08:13 schrieb Maruan Sahyoun:
> Hi,
>
>
>> Am 30.07.2016 um 07:25 schrieb Tilman Hausherr <TH...@t-online.de>:
>>
>> Read this:
>> https://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PPKAppearances.pdf
>>
>> what you need is the n2 layer. We have only the n0 layer.
>>
>> There's also something about the n2 layer here
>> https://issues.apache.org/jira/browse/PDFBOX-3198
>>
>> but without a working example.
>>
>> Also have a look at your file with PDFDebugger.
>>
>> I'll have a look at your files later.... be patient\u2026.
> Ill hack something together later today. Moving forward with 2.1 there will be an additional approach which will work similar to adding a signature field and using a signature design in Adobe Acrobat. This will not be compatible with the current PDVisibleSignatureDesigner etc.
>
> @Tilman - I havn't seen any files. Could you forward them to me or are they confidential?

There were inline links in his msg of 29.07.2016 19:39

Tilman


>
> BR
> Maruan
>
>> Tilman
>>
>> 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)
>>>
>>> [ ]'s
>>>
>>> Diego Azevedo
>>>
>>> On 29/07/2016 16:44, Maruan Sahyoun wrote:
>>>> Hi,
>>>>> Am 29.07.2016 um 19:39 schrieb Diego Azevedo <da...@esec.com.br>:
>>>>>
>>>>> 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: users-unsubscribe@pdfbox.apache.org
>>>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>>>
>>>>> -- 
>>>>> _______________________________________________
>>>>>
>>>>> <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: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Visible Signature with text

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,


> Am 30.07.2016 um 07:25 schrieb Tilman Hausherr <TH...@t-online.de>:
> 
> Read this:
> https://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PPKAppearances.pdf
> 
> what you need is the n2 layer. We have only the n0 layer.
> 
> There's also something about the n2 layer here
> https://issues.apache.org/jira/browse/PDFBOX-3198
> 
> but without a working example.
> 
> Also have a look at your file with PDFDebugger.
> 
> I'll have a look at your files later.... be patient….

Ill hack something together later today. Moving forward with 2.1 there will be an additional approach which will work similar to adding a signature field and using a signature design in Adobe Acrobat. This will not be compatible with the current PDVisibleSignatureDesigner etc.

@Tilman - I havn't seen any files. Could you forward them to me or are they confidential?

BR
Maruan

> 
> Tilman
> 
> 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)
>> 
>> [ ]'s
>> 
>> Diego Azevedo
>> 
>> On 29/07/2016 16:44, Maruan Sahyoun wrote:
>>> Hi,
>>>> Am 29.07.2016 um 19:39 schrieb Diego Azevedo <da...@esec.com.br>:
>>>> 
>>>> 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: users-unsubscribe@pdfbox.apache.org
>>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>> 
>>>> -- 
>>>> _______________________________________________
>>>> 
>>>> <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: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Visible Signature with text

Posted by Tilman Hausherr <TH...@t-online.de>.
Read this:
https://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PPKAppearances.pdf

what you need is the n2 layer. We have only the n0 layer.

There's also something about the n2 layer here
https://issues.apache.org/jira/browse/PDFBOX-3198

but without a working example.

Also have a look at your file with PDFDebugger.

I'll have a look at your files later.... be patient....

Tilman

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)
>
> [ ]'s
>
> Diego Azevedo
>
> On 29/07/2016 16:44, Maruan Sahyoun wrote:
>> Hi,
>>> Am 29.07.2016 um 19:39 schrieb Diego Azevedo <da...@esec.com.br>:
>>>
>>> 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: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>
>>> -- 
>>> _______________________________________________
>>>
>>> <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: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Visible Signature with text

Posted by Diego Azevedo <da...@esec.com.br>.
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 <da...@esec.com.br>:
>>
>> 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: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>
>> -- 
>> _______________________________________________
>>
>> <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: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Visible Signature with text

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,
> Am 29.07.2016 um 19:39 schrieb Diego Azevedo <da...@esec.com.br>:
> 
> 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: users-unsubscribe@pdfbox.apache.org 
>> For additional commands, e-mail: users-help@pdfbox.apache.org 
>> 
> 
> -- 
> _______________________________________________
> 
> <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: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Visible Signature with text

Posted by Diego Azevedo <da...@esec.com.br>.
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 <https://drive.google.com/open?id=0B9u-J6HILTH6UjR4NFp3bFdPMUk>

But when I try to add this visible layer, the retangle becomes blank: 
link <https://drive.google.com/open?id=0B9u-J6HILTH6VWxKR1dONDBTSkU>

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?

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: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>

-- 
*_______________________________________________

Diego Azevedo
Desenvolvedor
E-SEC Segurança Digital
www.esec.com.br <http://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


Re: Visible Signature with text

Posted by Tilman Hausherr <TH...@t-online.de>.
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: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org