# Signature Workflow

This chapter provides a detailed guide on how to use the SignatureWorkflowService API to control the signature workflow in the UIExtension layer, enabling the implementation of custom signature processes. Through this API, developers can perform operations such as setting signer override strategies, customizing signature workflows, and managing the verification process.


SignatureWorkflowService is a service class designed to manage signature workflows, offering the following functionalities:

  • Set Signer Override Strategy: Customize the display format of signer names.
  • Customize Signature Workflow: Override the default signature workflow with custom signature settings.
  • Customize Verification Workflow: Override the default signature verification process with custom verification logic.

# Method Description

# setSignerOverridePolicy(overridePolicy: SignerOverridePolicy): void

Set the signer override policy. If this policy is set, when users click on a signed signature field to view its properties, the viewer will invoke this policy. This policy allows you to choose to replace the original signer name with a custom signer name.

Parameters:

  • overridePolicy: SignerOverridePolicy - The override policy to be set.

Example:

const service = pdfui.getSignatureWorkflowService();
service.setSignerOverridePolicy(async (field) => {
    // Implement logic to determine the signer
    return 'the signer';
});

# overrideSigningWorkflow(signingWorkflowHandler: SigningWorkflowHandler): void

Override the signing process for all signature fields. If you provide a signing callback, when users click on a signature field to sign, Foxit PDF SDK for Web will no longer use the built-in signing UI. Instead, it will invoke the callback function you provide and use the signature returned by the callback for signing.

Developers can leverage this feature to implement a custom signing UI and workflow, thereby optimizing the user experience and the signing process.

Parameters:

  • signingWorkflowHandler: SigningWorkflowHandler - 要调用的签名回调。

Example:

const service = pdfui.getSignatureWorkflowService();
service.overrideSigningWorkflow(async (field) => {
    // Implement logic to determine the signature settings
    return {
        filter: 'Adobe.PPKLite',
        subfilter: 'adbe.pkcs7.detached',
        signer: 'Signer Name',
        distinguishName: '',
        location: '',
        reason: '',
        defaultContentsLength: 0,
        flag: 0,
        sign: async (signInfo: object, plainBuffer: ArrayBuffer) => {
            // Implement logic to sign the document
            return plainBuffer;
        }
    }
});

# overrideVerifyWorkflow(verifyCallback: VerifyWorkflowHandler): void

Override the Verification process for all signature fields. If a custom Verification callback is set, it will be used to verify the signatures.

Parameters:

  • verifyCallback: VerifyWorkflowHandler - The Verification callback to be invoked.

Example:

const service = pdfui.getSignatureWorkflowService();
service.overrideVerifyWorkflow(async (signature) => {
    // Implement logic to verify the signature
    return 0;
});

# verifySignature(signature: ISignatureField): Promise<number>

Verify the given signature field. If a custom Verification callback is set, it will be used to verify the signature; otherwise, the built-in verification method of the signature field will be used.

Parameters:

  • signature: ISignatureField - The signature field to be verified.

Return Value:

  • Promise<number> - Return a Promise object that resolves to the verification result.

# Integration Example

Below is a complete example demonstrating how to use SignatureWorkflowService to manage the signature workflow. With this approach, developers can flexibly control the signing process to meet various custom requirements.

const service = pdfui.getSignatureWorkflowService();

//  Set the signer override policy 
service.setSignerOverridePolicy(async (field) => {
    // Implement logic to determine the signer 
    return 'the signer';
});

// Override the signing workflow
service.overrideSigningWorkflow(async (field) => {
    // Implement logic to determine the signature settings  
    return {
        filter: 'Adobe.PPKLite',
        subfilter: 'adbe.pkcs7.detached',
        signer: 'Signer Name',
        distinguishName: '',
        location: '',
        reason: '',
        defaultContentsLength: 0,
        flag: 0,
        sign: async (signInfo: object, plainBuffer: ArrayBuffer) => {
            // Implement logic to sign the document 
            return plainBuffer;
        }
    }
});

// Override the verification workflow  
service.overrideVerifyWorkflow(async (signature) => {
    // Implement logic to verify the signature 
    return 0;
});

// Verify the signature
const signatureField = ...; // Get signature fields 
const result = await service.verifySignature(signatureField);
console.log('Verification result:', result);