Sample code for 30+ languages & platforms
Java

Sign PDF with Invisible Signature

See more PDF Signatures Examples

Demonstrates how to sign a PDF with an invisible signature.

Note: This example requires Chilkat v9.5.0.85 or greater.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.Cert;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Pdf;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Pdf pdf = new Pdf();

        // Load a PDF to be signed.
        // The "hello.pdf" is available at https://chilkatsoft.com/hello.pdf
        try {
            pdf.loadFile("qa_data/pdf/hello.pdf");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Options for signing are specified in JSON.
        JsonObject json = new JsonObject();

        // In most cases, the signingCertificateV2 and signingTime attributes are required.
        json.updateInt("signingCertificateV2", 1);
        json.updateInt("signingTime", 1);

        // Indicate that the signature will be invisible.
        json.updateBool("invisibleSignature", true);

        // Load the signing certificate. (Use your own certificate.)
        Cert cert = new Cert();
        try {
            cert.loadPfxFile("qa_data/pfx/myPdfSigningCert.pfx", "secret");

            // Tell the pdf object to use the certificate for signing.
            pdf.setSigningCert(cert);

            pdf.signPdf(json, "qa_output/hello_signed.pdf");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("PDF successfully signed with an invisible signature.");

        // An invisible signature has no appearance within the PDF document itself,
        // but Adobe Acrobat will indicate the document is signed in a toolbar, as shown here:
        // image
    }
}