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 searchprocess 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 sender, ProcessStartEventArgs args)
{
    System.out.print("Search process started at "+args.getStarted()+" with "+args.getTotalSignatures()+" total signatures to be put in document");
}

Implement method for SearchProgress event

 private static void onSearchProgress(Signature sender, ProcessProgressEventArgs args)
{
    System.out.print("Search progress. Processed "+args.getProcessedSignatures()+" signatures. Time spent "+args.getTicks()+" mlsec");
}

Implement method for SearchCompleted event

private static void onSearchCompleted(Signature sender, ProcessCompleteEventArgs args)
{
    System.out.print("Search process completed at "+args.getCompleted()+" with "+args.getTotalSignatures()+" total signatures. Process took "+args.getTicks()+" mlsec");
}

Subscribing for search process events

private static void onSearchStarted(Signature sender, ProcessStartEventArgs args)
{
    System.out.print("Search process started at "+args.getStarted()+" with "+args.getTotalSignatures()+" total signatures to be put in document");
}
 
private static void onSearchProgress(Signature sender, ProcessProgressEventArgs args)
{
    System.out.print("Search progress. Processed "+args.getProcessedSignatures()+" signatures. Time spent "+args.getTicks()+" mlsec");
}
 
private static void onSearchCompleted(Signature sender, ProcessCompleteEventArgs args)
{
    System.out.print("Search process completed at "+args.getCompleted()+" with "+args.getTotalSignatures()+" total signatures. Process took "+args.getTicks()+" mlsec");
}
 
public static void run()
{
    // The path to the documents directory.
    String filePath = Constants.SAMPLE_PDF;
 
    try {
        Signature signature = new Signature(filePath);
        signature.SearchStarted.add(new ProcessStartEventHandler() {
            public void invoke(Signature sender, ProcessStartEventArgs args) {
                onSearchStarted(sender, args);
            }
        });
 
 
        signature.SearchProgress.add(new ProcessProgressEventHandler() {
            public void invoke(Signature sender, ProcessProgressEventArgs args) {
                onSearchProgress(sender, args);
            }
 
 
        });
        signature.SearchCompleted.add(new ProcessCompleteEventHandler() {
            public void invoke(Signature  sender, ProcessCompleteEventArgs args) {
                onSearchCompleted(sender, args);
            }
        });
 
        BarcodeSearchOptions options = new BarcodeSearchOptions();
 
        // specify special pages to search on
        options.setAllPages(false);   
 
        // search for signatures in document
        List<BarcodeSignature> signatures = signature.search(BarcodeSignature.class,options);
        System.out.print("\nSource document contains following signatures.");
        for (BarcodeSignature barcodeSignature : signatures)
        {
            System.out.print("Barcode signature found at page "+barcodeSignature.getPageNumber()+" with type "+barcodeSignature.getEncodeType()+" and text " + barcodeSignature.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.