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
- TextSignatureImplementation.Stamp - text stamp component (label) on the document page.
- TextSignatureImplementation.Annotation - text annotation with different appearances settings. This implementation depends of document type.
- TextSignatureImplementation.Image - text will be transformed to image and put to document page. This implementation makes sense when there’s a need to adjust extended appearances effects that is possible with image adjustment only (like opacity, free rotation, fading, shadows etc).
- TextSignatureImplementation.Sticker - text sticker icon with different appearances settings. This implementation depends of document type.
- TextSignatureImplementation.FormField - this type is used to update existing Form Fields in the document. For this purpose please user property FormTextFieldTitle to setup Form Field name and property FormTextFieldType to specify type of Form Field.
- TextSignatureImplementation.Watermark - text watermark along the document page under all document components. This implementation depends of document type.
Here are the steps to add Text signature into document with various text signature implementation types with GroupDocs.Signature:
- Create new instance of Signature class and pass source document path as a constructor parameter.
- Instantiate the TextSignOptions object with all required additional options.
- set property SignatureImplementation of TextSignOptions object with required value from enumeration type TextSignatureImplementation.
- Call sign method of Signature class instance and pass initialized TextSignOptions instance to it.
- Analyze SignResult result to check newly created signatures if needed.
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:
- GroupDocs.Signature for .NET examples, plugins, and showcase
- GroupDocs.Signature for Java examples, plugins, and showcase
- Document Signature for .NET MVC UI Example
- Document Signature for .NET App WebForms UI Example
- Document Signature for Java App Dropwizard UI Example
- Document Signature for Java Spring UI Example
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.