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

    Visible Digital Certification

    In much the same way that PDF documents can be digitally signed (as was demonstrated above) they can also be certified. Digitally certifying a PDF establishes that a document will not be changed in anyway except a limited edits that the owner of the digital ID can specify (namely form filling and commenting). Also similar to digital signatures, digital certificates can either be a visual part of the PDF document (using a defined Signature Field) or it can be just noted as part of the documents properties and not visible from the PDF pages content.

    To add a certification as visible fields in the document you must first create and add a Signature Field to a Page (this defines where the certificate will be visible on that page). Then create a Certificate object (based on the personal information exchange file or PFX and the password). Finally you must call the Document object's Certify method passing in the name of the Signature Field, the Certificate object as well as a CertifyingPermission (this specifies whether any changes such as form filling or comments will be allowed).

    The below example demonstrates adding a visible digital certification 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.certify("SigField", certificate,CertifyingPermission.NoChangesAllowed);
         document.draw("[PhysicalPath]/MyDocument.pdf");
    

    Invisible Digital Certification

    Alternatively, digital certifications 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. A document should only be certified once.
    The below example demonstrates adding an invisible digital certification 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.certify("NonExistingField", certificate,CertifyingPermission.NoChangesAllowed);
         document.draw("[PhysicalPath]/MyDocument.pdf");