Subscribing for search process events

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

  • SearchStartedย to handle process start event. This event is occur onceย Search method is called
  • SearchProgressย to handle progress event. This event occursย each time on searching each document page.
  • SearchCompletedย to handle completion event. This event occursย onceย Search process was completed.

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

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

Implement method for SearchStarted event

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

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

Implement method for SearchProgress event

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

Implement method for SearchCompleted event

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

Subscribing for search process events

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

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

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

public static void Run()
{
    using (Signature signature = new Signature("SignedSample.pdf"))
    {
        signature.SearchStarted += OnSearchStarted;
        signature.SearchProgress += OnSearchProgress;
        signature.SearchCompleted += OnSearchCompleted;
        BarcodeSearchOptions options = new BarcodeSearchOptions()
        {
            // specify special pages to search on
            AllPages = true
        };
        // search for signatures in document
        List<BarcodeSignature> signatures = signature.Search<BarcodeSignature>(options);
        Console.WriteLine("\nSource document contains following signatures.");
        foreach (var barcodeSignature in signatures)
        {
            Console.WriteLine("Barcode signature found at page {0} with type {1} and text {2}",
                  barcodeSignature.PageNumber, barcodeSignature.EncodeType, barcodeSignature.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.