Sign document with different Text signature implementation

GroupDocs.Signature provides TextSignOptions class with property SignatureImplementation of enumeration type TextSignatureImplementation to specify various implementations of Text Signatures with following values and its meaning

Here are the steps to add Text signature into document with various text signature implementation types with GroupDocs.Signature:

Sign document with Text signature and Stamp implementation type

This example shows how to add Text signature with Stamp signature implementation to document.

Signature signature = new Signature("sample.pdf");
{
    TextSignOptions options = new TextSignOptions("John Smith");
    
        // set alternative signature implementation on document page
    options.setSignatureImplementation(TextSignatureImplementation.Stamp);
        // set alignment
    options.setVerticalAlignment(VerticalAlignment.Top);
    options.setHorizontalAlignment(HorizontalAlignment.Right);
        // set margin with 20 pixels for all sides
    options.setMargin(new Padding(20));
    
    // sign document to file
    SignResult signResult = signature.sign("signed.pdf", options);
    // analyzing result
    System.out.print("List of newly created signatures:");
    int number = 1;
    for (BaseSignature temp : signResult.getSucceeded())
    {
        System.out.print("Signature #"+number+++": Type: "+temp.getSignatureType()+" Id:"+temp.getSignatureId()+
                ", Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight());
    }
}

Sign document with Text signature and Annotation implementation type

This example shows how to add Text signature with Annotation signature implementation to document.

Signature signature = new Signature("sample.pdf");
{
    TextSignOptions options = new TextSignOptions("John Smith");

        // set alternative signature implementation on document page
    options.setSignatureImplementation(TextSignatureImplementation.Annotation);
        // for Pdf document type ther's ability to setup exteneded appearences
    PdfTextAnnotationAppearance appearance =  new PdfTextAnnotationAppearance();
    Border border= new Border();
    border.setColor(Color.BLUE);
    border.setDashStyle(DashStyle.Dash);
    border.setWeight(2);
    appearance.setBorder(border);
    appearance.setBorderEffect(PdfTextAnnotationBorderEffect.Cloudy);
    appearance.setBorderEffectIntensity(2);
    appearance.setHCornerRadius(10);
        // text content of an annotation
    appearance.setContents("Sample");
    appearance.setSubject("Sample subject");
    appearance.setTitle("Sample Title");
    options.setAppearance(appearance);
        // set alignment
    options.setVerticalAlignment(VerticalAlignment.Top);
    options.setHorizontalAlignment(HorizontalAlignment.Right);
        // set margin with 20 pixels for all sides
    options.setMargin(new Padding(20));

        // sign document to file
    SignResult signResult = signature.sign("signed.pdf", options);
        // analyzing result
    // analyzing result
    System.out.print("List of newly created signatures:");
    int number = 1;
    for (BaseSignature temp : signResult.getSucceeded())
    {
        System.out.print("Signature #"+number+++": Type: "+temp.getSignatureType()+" Id:"+temp.getSignatureId()+
                ", Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight());
    }
}

Sign document with Text signature and Image implementation type

This example shows how to add Text signature with Image signature implementation to document.

Signature signature = new Signature("sample.pdf");
{
    TextSignOptions options = new TextSignOptions("John Smith");            
        // set alternative signature implementation on document page
    options.setSignatureImplementation(TextSignatureImplementation.Image);
        // set alignment
    options.setVerticalAlignment(VerticalAlignment.Top);
    options.setHorizontalAlignment(HorizontalAlignment.Right);
        // set margin with 20 pixels for all sides
    options.setMargin(new Padding(20));            
        // sign document to file
    SignResult signResult = signature.sign("signed.pdf", options);
        // analyzing result
    System.out.print("List of newly created signatures:");
    int number = 1;
    for (BaseSignature temp : signResult.getSucceeded())
    {
        System.out.print("Signature #"+number+++": Type: "+temp.getSignatureType()+" Id:"+temp.getSignatureId()+
                ", Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight());
    }
}

Sign document with Text signature and Sticker implementation type

This example shows how to add Text signature with Sticker signature implementation to document.

Signature signature = new Signature("sample.pdf");
{
    TextSignOptions options = new TextSignOptions("John Smith");
    
        // set alternative signature implementation on document page
    options.setSignatureImplementation(TextSignatureImplementation.Sticker);

        // set alignment
    options.setVerticalAlignment(VerticalAlignment.Top);
    options.setHorizontalAlignment(HorizontalAlignment.Right);
        // set margin with 20 pixels for all sides
    options.setMargin(new Padding(20));
    
    // sign document to file
    SignResult signResult = signature.sign("signed.pdf", options);
    // analyzing result
    System.out.print("List of newly created signatures:");
    int number = 1;
    for (BaseSignature temp : signResult.getSucceeded())
    {
        System.out.print("Signature #"+number+++": Type: "+temp.getSignatureType()+" Id:"+temp.getSignatureId()+
                ", Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight());
    }
}

Sign document with Text signature and Form Field implementation type

This example shows how to add Text signature with FormField signature implementation to document.

Signature signature = new Signature("sample.docx");
{
    TextSignOptions ffOptions1 = new TextSignOptions("John Smith");            
        // set alternative signature implementation on document page
    ffOptions1.setSignatureImplementation(TextSignatureImplementation.FormField);
    ffOptions1.setFormTextFieldType(FormTextFieldType.PlainText);
    ffOptions1.setFormTextFieldTitle("UserSignatureFullName");
    
    TextSignOptions ffOptions2 = new TextSignOptions("Document is approved");            
        // set alternative signature implementation on document page
    ffOptions2.setSignatureImplementation(TextSignatureImplementation.FormField);
    ffOptions2.setFormTextFieldType(FormTextFieldType.RichText);
    ffOptions2.setFormTextFieldTitle("UserSignatureComment");
    
    List<SignOptions> listOptions = new ArrayList<SignOptions>();
    listOptions.add(ffOptions1);
    listOptions.add(ffOptions2);
    // sign document to file
    SignResult signResult = signature.sign("signed.docx", listOptions);
    // analyzing result
    System.out.print("List of newly created signatures:");
    int number = 1;
    for (BaseSignature temp : signResult.getSucceeded())
    {
        System.out.print("Signature #"+number+++": Type: "+temp.getSignatureType()+" Id:"+temp.getSignatureId()+
                ", Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight());
    }
}

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.