Processes cancellation

Signature class supports cancellation for each of document processing (Sign, Verify, Search). The process cancellation happens over setting property getCancel of ProcessProgressEventArgs property in proper event handler.

  • for sign process this flag should be set to true in handler of SignProgress event. This event occurs each time on signing each signature was completed.
  • for verify process this flag should be set to true in handler of VerifyProgress event. This event occurs each time on verifying document page.
  • for search process this flag should be set to true in handler of SearchProgress event. This event occurs each time on searching document page per each options.  

Cancel signing process

Here are the steps to provide cancellation for signing process with GroupDocs.Signature:

  • Define SignProgress event handler delegates to conditionally cancel the process.
  • Create new instance of Signature class and pass source document path or stream as a constructor parameter.
  • Subscribe for SignProgress event with proper handler method
  • Instantiate required SignOptions object 
  • Call sign method of Signature class instance and pass signature options in it
private static void onSignProgress(Signature sender, ProcessProgressEventArgs args) {
    // check if process takes more than 1 second (1000 milliseconds) processing cancellation
    if (args.getTicks() > 1000) {
        args.setCancel(true);
        System.out.print("Sign progress was cancelled. Time spent " + args.getTicks() + " mlsec");
    }
}
 
public static void run() {   
    try {
        Signature signature = new Signature("Sample.pdf");
        signature.SignProgress.add(new ProcessProgressEventHandler() {
            public void invoke(Signature sender, ProcessProgressEventArgs args) {
                onSignProgress(sender, args);
            }
        });
 
        TextSignOptions options = new TextSignOptions("John Smith") {
            // ...
        };
 
        // sign document to file
        signature.sign("Signed.pdf", options);
            System.out.print("\nSource document signed successfully.\nFile saved at " + outputFilePath);
 
    } catch (Exception e) {
        throw new GroupDocsSignatureException(e.getMessage());
    }
}

Cancel verification process

Here are the steps to provide cancellation for verification process with GroupDocs.Signature:

  • Define VerifyProgress event handler delegates to conditionally cancel the process.
  • Create new instance of Signature class and pass source document path or stream as a constructor parameter.
  • Subscribe for VerifyProgress event with proper handler method
  • Instantiate required VerifyOptions  object 
  • Call verify method of Signature class instance and pass verification options in it.
private static void onVerifyProgress(Signature sender, ProcessProgressEventArgs args) {
    // check if process takes more than 1 second (1000 milliseconds) processing cancellation
    if (args.getTicks() > 1000) {
        args.setCancel(true);
        System.out.print("Verify progress was cancelled. Time spent " + args.getTicks() + " mlsec");
    }
}
 
public static void run() {   
 
    try {
        Signature signature = new Signature("SampleSigned.pdf");
        signature.VerifyProgress.add(new ProcessProgressEventHandler() {
            public void invoke(Signature sender, ProcessProgressEventArgs args) {
                onVerifyProgress(sender, args);
            }
        });
 
        TextVerifyOptions options = new TextVerifyOptions("John Smith")
        {
            // ...
        };
 
        // sign document to file
        VerificationResult result = signature.verify(options);
    } catch (Exception e) {
        throw new GroupDocsSignatureException(e.getMessage());
    }
}

Cancel search process

Here are the steps to provide cancellation of searching process with GroupDocs.Signature:

  • Define SearchProgress event handler delegates to conditionally cancel the process.
  • Create new instance of Signature class and pass source document path or stream as a constructor parameter.
  • Subscribe for SearchProgress event with proper handler method
  • Instantiate required SearchOptions object 
  • Call search method of Signature class instance and pass search options in it
private static void onSearchProgress(Signature sender, ProcessProgressEventArgs args) {
    // check if process takes more than 1 second (1000 milliseconds) processing cancellation
    if (args.getTicks() > 1000) {
        args.setCancel(true);
        System.out.print("Search progress was cancelled. Time spent " + args.getTicks() + " mlsec");
    }
}
 
public static void run() {   
 
    try {
        Signature signature = new Signature("SampleSigned.pdf");
        signature.SearchProgress.add(new ProcessProgressEventHandler() {
            public void invoke(Signature sender, ProcessProgressEventArgs args) {
                onSearchProgress(sender, args);
            }
        });
 
        QrCodeSearchOptions options = new QrCodeSearchOptions(QrCodeTypes.QR) {
            // ...
        };
 
        // search for signatures in document
        List<QrCodeSignature> signatures = signature.search(QrCodeSignature.class, options);
        System.out.print("\nSource document contains following signatures.");
        for(QrCodeSignature qr_signature : signatures)
        {
            System.out.print("QRCode signature found at page "+qr_signature.getPageNumber()+" with type "+ qr_signature.getEncodeType()+" and text " + qr_signature.getText());
        }
    } catch (Exception e) {
        throw new GroupDocsSignatureException(e.getMessage());
    }
}

More resources

GitHub Examples 

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App 

Along with full-featured .NET library we provide simple, but powerful free Apps.
You are welcome to eSign PDF, Word, Excel, PowerPoint documents with free to use online GroupDocs Signature App.