Subscribing for signing process events

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

  • SignStarted to handle process start event. This event is occur once sign method is called
  • SignProgress to handle progress event. This event occurs each time on signing each signature was completed.
  • SignCompleted to handle completion event. This event occurs once sign process was completed.    

Here are the steps to subscribe for signing 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 SignOptions object 
  • Call sign method of Signature class instance and pass signature options in it

Implement method for SignStarted event

GroupDocs.Signature expects ProcessStartEventHandler delegate to subscribe for SignStarted event

private static void onSignStarted(Signature sender, ProcessStartEventArgs args)
{
    System.out.print("Sign process started at "+args.getStarted()+" with "+args.getTotalSignatures()+" total signatures to be put in document");
}

Implement method for SignProgress event

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

Implement method for SignCompleted event

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

Subscribing for signing process events

private static void onSignStarted(Signature sender, ProcessStartEventArgs args)
{
    System.out.print("Sign process started at "+args.getStarted()+" with "+args.getTotalSignatures()+" total signatures to be put in document");
}
 
private static void onSignProgress(Signature sender, ProcessProgressEventArgs args)
{
    System.out.print("Sign progress. Processed "+args.getProcessedSignatures()+" signatures. Time spent "+args.getTicks()+" mlsec");
}
 
private static void onSignCompleted(Signature sender, ProcessCompleteEventArgs args)
{
    System.out.print("Sign process completed at "+args.getCompleted()+" with "+args.getTotalSignatures()+" total signatures. Process took "+args.getTicks()+" mlsec");
}
 
 
/**
 * Sign document with text signature applying specific options
 */
public static void run()
{    
    try {
        Signature signature = new Signature("sample.pdf");
        signature.SignStarted.add(new ProcessStartEventHandler() {
            public void invoke(Signature sender, ProcessStartEventArgs args) {
                onSignStarted(sender, args);
            }
        });
        signature.SignProgress.add(new ProcessProgressEventHandler() {
            public void invoke(Signature sender, ProcessProgressEventArgs args) {
                onSignProgress(sender, args);
            }
        });
        signature.SignCompleted.add(new ProcessCompleteEventHandler() {
            public void invoke(Signature  sender, ProcessCompleteEventArgs args) {
                onSignCompleted(sender, args);
            }
        });
 
        TextSignOptions options = new TextSignOptions("John Smith");
 
        // set signature position 
        options.setLeft(100);
        options.setTop(100);
 
        signature.sign("signed.pdf", options);
        System.out.print("\nSource document signed successfully.\nFile saved at " + outputFilePath);
 
    } 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.

© Aspose Pty Ltd 2001-2022. All Rights Reserved.