ceTe Software Help Library for Java September - 2021
DynamicPDF Generator for Java / Programming with Generator for Java / Digital Signing and Certifying / Digital Signing
In This Topic
    Digital Signing
    In This Topic

    Visible Digital Signatures

    A PDF document can have a digital ID applied to it in order to be digitally signed. That digital ID can either be added to visually appear on the page of the PDF (through a Signature Field) or they can be added so that the digital signature is just a part of the document's properties (and not a visible part of any pages).

    To add signatures as visible fields in the document you must first create and add a Signature Field to a Page (this defines where the signature will be visible on that page), then create a Certificate object (based on the personal information exchange file or PFX and the password) then finally you must call the Document object's Sign method passing in the name of the Signature Field and the Certificate object.

    The below example demonstrates adding a visible digital signature to a PDF document:

    [Java]
         Document document = new Document();
         Page page = new Page();
    
         //Create & add Signature Form Field
         Signature signature = new Signature("SigField", 10, 10, 250, 100);
         page.getElements().add(signature);
         document.getPages().add(page);
         Certificate certificate = new Certificate("[PhysicalPath]/JohnDoe.pfx", "password");
    
         // Field name should be one of the signature field name 
         document.sign("SigField", certificate);
         document.draw("[PhysicalPath]/MyDocument.pdf");
    

     

    Invisible Digital Signatures

    Alternatively, digital signatures can be added so that they are part of the Document but not actually viewable from any of the pages. To accomplish this just omit the creating of the Signature Field from the above example. In the Document's Sign method make sure to specify a string that does not match the name of any form fields on the document. If the field name passed into the Document's Sign method does match a field but it is a non-signature field then the document will be left unsigned. Also worth noting here is that the Document's Sign method can only be called once (allowing only one signature to be associated with each document).

    The below example demonstrates adding an invisible digital signature to a PDF document:

    [Java]
         Document document = new Document();
         Page page = new Page();
    
         document.getPages().add(page);
         Certificate certificate = new Certificate("[PhysicalPath]/JohnDoe.pfx", "password");
    
         // Field name should not match any field name in the document
         document.sign("NonExistingField", certificate);
         document.draw("[PhysicalPath]/MyDocument.pdf");