# Signature Service API
# Overview
The SignatureService class is designed for customizing the PDF signature validation logic. By configuring a custom signature verification callback, developers can forward signature validation requests to backend services or integrate third-party verification mechanisms.
# Main Methods
# setVerifyHandler(handler: VerifySignatureHandler)
- Functionality: Set the signature verification callback function. When the PDF viewer needs to validate a signature, it will invoke this
handler. - Parameters:
handler: A function of typeVerifySignatureHandler, which handles signature verification.
- Return Value: None
- Version: Supported since version 11.0.0
# Description of handler
handleris an asynchronous function, typically defined as followsasync (signatureField, plainContent, signedData, hasDataOutOfScope) => { ... }Within the
handler, developers can access information related to the signature field (e.g.,filter,subfilter,signer) and forward the original content and signature data to backend services for validation.
# Signature Verification Process Description
The signature verification process is triggered in the following scenarios:
Triggered by JavaScript Action: For example, when the document is opened (PDFDoc open action) or when the mouse button is released over the annotation area (ANNOT_MOUSE_BUTTON_RELEASED), signature verification is performed automatically.
Triggered by User Action: When the user clicks on a signed signature field, the signature verification process is initiated.
Calling the
PDFSignature.verifyMethod: When using theverifymethod inPDFSignature, if theverifyHandleroption is not specified, thehandlerset viaSignatureService.setVerifyHandlerwill be used by default.
Note:
- The
PDFDoc.verifySignaturemethod does not use thehandlerset inSignatureServiceby default; you need to specify it explicitly.
- The
# Example
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
Must Set a Verification Callback: Before initiating the signature verification process, make sure to set the
handlerusingSignatureService.setVerifyHandler; otherwise, the verification process will throw an exception.Handler Return Value: The
handlershould return a numeric value representing the verification result (refer to the Form Signature Fields documentation for related information).Asynchronous Support: The
handlersupports asynchronous operations, making it convenient for integration with backend services.Scope of Applicability: The
handlerset inSignatureServiceis only effective for JavaScript Action verification processes and whenPDFSignature.verifydoes not specify ahandler. It does not apply toPDFDoc.verifySignature. :