Processes cancellation

Signature class supports cancellation for each of document processing (Sign, Verify, Search). The process cancellation happens over setting property Cancel 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.Ticks > 1000)
    {
        args.Cancel = true;
        Console.WriteLine("Sign progress was cancelled. Time spent {0} mlsec", args.Ticks);
    }
}
/// <summary>
/// Sign document with text signature applying specific options
/// </summary>
public static void Run()
{
    using (Signature signature = new Signature("sample.docx"))
    {
        signature.SignProgress += OnSignProgress;
        TextSignOptions options = new TextSignOptions("John Smith")
        {
            // ...
        };
        // sign document to file
        signature.Sign("signedSample", options);
    }
}

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.Ticks > 1000)
    {
        args.Cancel = true;
        Console.WriteLine("Sign progress was cancelled. Time spent {0} mlsec", args.Ticks);
    }
}
public static void Run()
{
    using (Signature signature = new Signature("SignedSample.pdf"))
    {
        signature.VerifyProgress += OnVerifyProgress;
        TextVerifyOptions options = new TextVerifyOptions("John Smith")
        {
            // ...
        };
        // sign document to file
        VerificationResult result = signature.Verify(options);
    }
}

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 requiredSearchOptions 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.Ticks > 1000)
    {
        args.Cancel = true;
        Console.WriteLine("Sign progress was cancelled. Time spent {0} mlsec", args.Ticks);
    }
}
public static void Run()
{
    using (Signature signature = new Signature("sampleSigned.pdf"))
    {
        signature.SearchProgress += OnSearchProgress;
        QrCodeSearchOptions options = new QrCodeSearchOptions(QRCodeTypes.QR)
        {
            // ...
        };
        // search for signatures in document
        List<QrCodeSignature> signatures = signature.Search<QrCodeSignature>(options);
        Console.WriteLine("\nSource document contains following signatures.");
        foreach (var QrCodeSignature in signatures)
        {
            Console.WriteLine("QRCode signature found at page {0} with type {1} and text {2}", QrCodeSignature.PageNumber, QrCodeSignature.EncodeType, QrCodeSignature.Text);
        }
    }
}

More resources

GitHub Examples

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

Free Online Apps

Along with the full-featured .NET library, we provide simple but powerful free online apps.

To sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the GroupDocs.Signature App Product Family.