com.cete.dynamicpdf.pageelements.forms
Class Signature



Example: This example shows how to create a signature and sign it with a certificate.

import com.cete.dynamicpdf.Certificate;
import com.cete.dynamicpdf.Document;
import com.cete.dynamicpdf.Page;
import com.cete.dynamicpdf.RgbColor;
import com.cete.dynamicpdf.pageelements.forms.Signature;
import java.io.FileNotFoundException;

public class MyClass {
       public static void main(String args[]) {
        // Create a PDF Document
        Document document = new Document();
        
        // Create a PDF Page
        Page page = new Page();
        
        // Create a signature form field
        Signature signature = new Signature("SigField", 10, 10, 300, 100);
        
        // Set a full background image
        try {
            signature.getFullPanel().setImage("[PhysicalPath]/MyImage.gif");
        } catch (FileNotFoundException ex) {
        }
        // Set new color property for the left panel text
        signature.getLeftPanel().setTextColor(RgbColor.getRed());

        // Add signature field to the page
        page.getElements().add(signature);

        // Add the page to the document
        document.getPages().add(page);

        // Create a Certificate from the file
        Certificate certificate = null;        
        try {
            certificate = new Certificate("[PhysicalPath]/MyPersonalCertificate.pfx", "MyPassword");
        } catch (FileNotFoundException ex) {
            System.out.println("File doesn't exist");
        }

        // Sign the document refering the sign field
        document.sign("SigField", certificate);
        
        // Save the PDF document.
        document.draw("[Physicalpath]/MyDocument.pdf");
       }
 }