pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maruan Sahyoun <sahy...@fileaffairs.de>
Subject Re: Visible Signature with text
Date Sat, 30 Jul 2016 06:13:23 GMT
Hi,


> Am 30.07.2016 um 07:25 schrieb Tilman Hausherr <THausherr@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 <dazevedo@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


Mime
View raw message