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:
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).User action: When the user clicks a signed signature field.
PDFSignature.verify: When you callverifyonPDFSignaturewithout averifyHandleroption, the handler set bySignatureService.setVerifyHandleris used by default.
- Note:
PDFDoc.verifySignaturedoes not use the handler fromSignatureServiceby 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.setVerifyHandlerbefore verification runs; otherwise verification throws.Return value:
handlershould return a numeric verification result (see Form signature fields for status values).Async:
handlersupports async integration with backend services.Scope: The
SignatureServicehandler applies to JavaScript Action verification andPDFSignature.verifywhen nohandleris passed; it does not apply toPDFDoc.verifySignature.