# 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
handler
is 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.verify
Method: When using theverify
method inPDFSignature
, if theverifyHandler
option is not specified, thehandler
set viaSignatureService.setVerifyHandler
will be used by default.
Note:
- The
PDFDoc.verifySignature
method does not use thehandler
set inSignatureService
by 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
handler
usingSignatureService.setVerifyHandler
; otherwise, the verification process will throw an exception.Handler Return Value: The
handler
should return a numeric value representing the verification result (refer to the Form Signature Fields documentation for related information).Asynchronous Support: The
handler
supports asynchronous operations, making it convenient for integration with backend services.Scope of Applicability: The
handler
set inSignatureService
is only effective for JavaScript Action verification processes and whenPDFSignature.verify
does not specify ahandler
. It does not apply toPDFDoc.verifySignature
. :