Skip to content

Signature service API ​

Introduction ​

The SignatureService class customizes PDF signature verification logic. Set a custom verify handler to forward verification to your backend or a third-party service.

Main methods ​

setVerifyHandler ​

Purpose ​

Sets the signature verification callback. The viewer calls this handler when it needs to verify a signature.

Parameters ​

  • handler: VerifySignatureHandler — Verification handler function.

Returns ​

  • None

Version ​

  • Supported since 11.0.0

About handler

handler is an async function, typically:

js
async (signatureField, plainContent, signedData, hasDataOutOfScope) => { ...
}

Inside handler, you can read signature field metadata (such as filter, subfilter, and signer) and send plain content and signed data to your backend for verification.

Verification flow ​

Verification runs in these situations:

  1. JavaScript action: For example when the document opens (PDFDoc open action) or when the mouse button is released over an annotation ( ANNOT_MOUSE_BUTTON_RELEASED).

  2. User action: When the user clicks a signed signature field.

  3. PDFSignature.verify: When you call verify on PDFSignature without a verifyHandler option, the handler set by SignatureService.setVerifyHandler is used by default.

  • Note:
    • PDFDoc.verifySignature does not use the handler from SignatureService by default; specify one explicitly when needed.

Example ​

js
const service = pdfViewer.getSignatureService();
service.setVerifyHandler(async (signatureField, plainContent, signedData, hasDataOutOfScope) => {
    const filter = await signatureField.getFilter();
    const subfilter = await signatureField.getSubfilter();
    const signer = await signatureField.getSigner();

    const formdata = new FormData();
    formdata.append("filter", filter);
    formdata.append("subfilter", subfilter);
    formdata.append("signer", signer);
    formdata.append("plainContent", new Blob([plainContent]), "plainContent");
    formdata.append("signedData", new Blob([signedData]), "signedData");

    const response = await fetch('https://<server>:<port>/<path/to/>verify', {
        method: 'POST',
        body: formdata
    });
    return parseInt(await response.text());
});

Notes ​

  • Set a verify handler: Call SignatureService.setVerifyHandler before verification runs; otherwise verification throws.

  • Return value: handler should return a numeric verification result (see Form signature fields for status values).

  • Async: handler supports async integration with backend services.

  • Scope: The SignatureService handler applies to JavaScript Action verification and PDFSignature.verify when no handler is passed; it does not apply to PDFDoc.verifySignature.