Subscribing for verification process events

Signature class contains several events that are being called for different verification process stages

  • VerifyStartedย to handle process start event. This event is occur onceย Verifyย method is called
  • VerifyProgressย to handle progress event. This event occursย each time on verifying each signature was completed.
  • VerifyCompletedย to handle completion event. This event occursย onceย Verifyย process was completed.

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

  • Define required handler delegates to process signing events.
  • Create new instance ofย Signatureย class and pass source document path or stream as a constructor parameter.
  • Subscribe for required events
  • Instantiate requiredย VerifyOptionsย object
  • Callย Verifyย method ofย Signature class instance and pass verify options in it

Implement method for VerifyStarted event

GroupDocs.Signature expectsย ProcessStartEventHandlerย delegate to subscribe forย VerifyStartedย event

private static void OnVerifyStarted(Signature signature, ProcessStartEventArgs args)
{
    Console.WriteLine("Verify process started at {0} with {1} total signatures to be put in document", args.Started, args.TotalSignatures);
}

Implement method for VerifyProgress event

 private static void OnVerifyProgress(Signature signature, ProcessProgressEventArgs args)
 {
     Console.WriteLine("Verify progress. Processed {0} signatures. Time spent {1} mlsec", args.ProcessedSignatures, args.Ticks);
 }

Implement method for VerifyCompleted event

private static void OnVerifyCompleted(Signature signature, ProcessCompleteEventArgs args)
{
    Console.WriteLine("Verify process completed at {0} with {1} total signatures. Process took {2} mlsec", args.Completed, args.TotalSignatures, args.Ticks);
}

Subscribing for verification process events

private static void OnVerifyStarted(Signature sender, ProcessStartEventArgs args)
{
    Console.WriteLine("Verify process started at {0} with {1} total signatures to be put in document", args.Started, args.TotalSignatures);
}
/// <summary>
/// Defines on progress event
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private static void OnVerifyProgress(Signature sender, ProcessProgressEventArgs args)
{
    Console.WriteLine("Verify progress. Processed {0} signatures. Time spent {1} mlsec", args.ProcessedSignatures, args.Ticks);
}
/// <summary>
/// Defines on completed event
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private static void OnVerifyCompleted(Signature sender, ProcessCompleteEventArgs args)
{
    Console.WriteLine("Verify process completed at {0} with {1} total signatures. Process took {2} mlsec", args.Completed, args.TotalSignatures, args.Ticks);
}
/// <summary>
/// Verify document with text signature applying specific options and subscribe for events
/// </summary>
public static void Run()
{
    // The path to the documents directory.
    string filePath = Constants.SAMPLE_PDF;
    using (Signature signature = new Signature(filePath))
    {
        signature.VerifyStarted += OnVerifyStarted;
        signature.VerifyProgress += OnVerifyProgress;
        signature.VerifyCompleted += OnVerifyCompleted;
        TextVerifyOptions options = new TextVerifyOptions("John Smith")
        {
           AllPages = true
        };
        // verify document
        VerificationResult result = signature.Verify(options);
        if (result.IsValid)
        {
            Console.WriteLine("\nDocument was verified successfully!");
        }
        else
        {
            Console.WriteLine("\nDocument failed verification process.");
        }
    }
}

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.