pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diego Azevedo <dazev...@esec.com.br>
Subject Re: Visible Signature with text
Date Fri, 29 Jul 2016 17:39:33 GMT
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


Mime
View raw message