eSign document with Form Field signature
What is a Form Field?
A form field is the interactive element located on document page that allows user data input through various control types like free input text box, multi-line text box, check boxes, drop down lists etc. Different document types support specific list of form field types. These elements are used to collect information from user on template form. Each Form Field element has an unique name, settings and value field. Form Fields should have unique names within the form. Picture below demonstrates possible document page with form fields.
How to eSign document with Form Field signature
GroupDocs.Signature supports creation of new form fields or update existing ones within the documents. Class FormFieldSignOptions specifies different options for Form Field signature. The FormFieldSignOptions class contains one FormFieldSignature object to put to the document.
Here are the list of different Form Field signature classes that could be set to FormFieldSignOptions
- TextFormFieldSignature - represents text input form field on document page.
- CheckboxFormFieldSignature - represents check box field on the document page.
- ComboboxFormFieldSignature - represents combo box field signature input with list of possible options on document page.
- RadioButtonFormFieldSignature - represents radio button signature on document page.
- DigitalFormFieldSignature - represents digital signature input form on document page.
Here are the steps to add Form Field signatures into document with GroupDocs.Signature:
- Create new instance of Signature class and pass source document path as a constructor parameter;
- Instantiate the FormFieldSignOptions object according to your requirements;
- Instantiate one of the objects - TextFormFieldSignature, CheckboxFormFieldSignature, ComboboxFormFieldSignature, RadioButtonFormFieldSignature or DigitalFormFieldSignature;
- Set FormFieldSignOptions Signature property with created object;
- Call Sign method of Signature class instance and pass FormFieldSignOptions to it.
NOTE: At the moment GroupDocs.Signature supports creation of Form Field signatures for PDF documents only.
This example shows how to sign PDF document with Form Field electronic signature on document page.
// The path to the documents directory.
string filePath = "sample.pdf";
string fileName = Path.GetFileName(filePath);
string outputFilePath = Path.Combine("C:\output", fileName);
using (Signature signature = new Signature(filePath))
{
// Instantiate text form field signature
FormFieldSignature textSignature = new TextFormFieldSignature("FieldText", "Value1");
// Instantiate options based on text form field signature
FormFieldSignOptions options = new FormFieldSignOptions(textSignature)
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Padding(10, 20, 0, 0),
Height = 10,
Width = 100
};
// Sign document and save to the file
signature.Sign(outputFilePath, options);
}
How to eSign document with existing Form Field signatures
GroupDocs.Signature for .NET also provides mechanism to update existing form fields signatures within the documents.
Class TextSignOptions allows to setup different options for Form Field signature
- property SignatureImplementation of enumeration type TextSignatureImplementation should be set to TextSignatureImplementation.FormField to update existing Form Fields in the document
- property FormTextFieldTitle must keep unique Form Field name
- property FormTextFieldType allows to specify type of Form Field.
Here are the steps to update existing form field signature within the document 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 TextSignatureImplementation.FormField value from enumeration type TextSignatureImplementation.
- Set properties FormTextFieldTitle and FormTextFieldType with proper values of form fields to update
- Call Sign method of Signature class instance and pass initialized TextSignOptions instance to it.
- Analyze SignResult result to check newly created signatures if needed.
This example shows how to e sign PDF document with existing Form Field electronic signature on document page and update its value.
// The path to the documents directory.
string filePath = "sample.pdf";
string fileName = Path.GetFileName(filePath);
string outputFilePath = Path.Combine("C:\output", fileName);
using (Signature signature = new Signature(filePath))
{
TextSignOptions ffOptions1 = new TextSignOptions("Document is approved")
{
// set alternative signature implementation on document page
SignatureImplementation = TextSignatureImplementation.FormField,
FormTextFieldType = FormTextFieldType.PlainText
};
TextSignOptions ffOptions2 = new TextSignOptions("John Smith")
{
// set alternative signature implementation on document page
SignatureImplementation = TextSignatureImplementation.FormField,
FormTextFieldType = FormTextFieldType.RichText,
FormTextFieldTitle = "UserSignatureFullName"
};
List<SignOptions> listOptions = new List<SignOptions>();
listOptions.Add(ffOptions1);
listOptions.Add(ffOptions2);
// sign document to file
SignResult signResult = signature.Sign(outputFilePath, listOptions);
}
Advanced Usage Topics
To learn more about document eSign features, please refer to the advanced usage section.
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.