Sign document with Form Field signature - advanced
GroupDocs.Signature provides FormFieldSignOptions class to specify different options for Form Field signature. The Form Field signature is special document predefined input field control with unique name inside the document content that expects some input from user.
At the moment GroupDocs.Siganture supports creation of Form Field signatures for Pdf documents only.
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 derived classes from FormFieldSignature object. It could be TextFormFieldSignature, CheckboxFormFieldSignature or DigitalFormFieldSignature.
- Set FormFieldSignOptions.Signature property with created object.
- Call Sign method of Signature class instance and pass FormFieldSignOptions to it.
- Analyze SignResult result to check newly created signatures if needed.
Following examples show different scenarios of using form fields on document page. These samples are supported for Pdf documents.
Sign Pdf document with various Form Field signatures
This example shows how to add various Form Field signature to document. See SignResult
using (Signature signature = new Signature("sample.pdf"))
{
List<SignOptions> listOptions = new List<SignOptions>();
// instantiate text form field signature
FormFieldSignature textSignature = new TextFormFieldSignature("tbData1", "Value-1");
// instantiate options based on text form field signature
FormFieldSignOptions optionsTextFF = new FormFieldSignOptions(textSignature)
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Padding(10, 20, 0, 0),
Height = 10,
Width = 100
};
// instantiate text form field signature
CheckboxFormFieldSignature chbSignature = new CheckboxFormFieldSignature("chbData1", true);
// instantiate options based on text form field signature
FormFieldSignOptions optionsTextCHB = new FormFieldSignOptions(chbSignature)
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Padding(0, 0, 0, 0),
Height = 10,
Width = 100,
};
// instantiate text form field signature
DigitalFormFieldSignature digSignature = new DigitalFormFieldSignature("dgData1");
// instantiate options based on text form field signature
FormFieldSignOptions optionsTextDIG = new FormFieldSignOptions(digSignature)
{
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Padding(0, 50, 0, 0),
Height = 10,
Width = 100,
};
listOptions.Add(optionsTextFF);
listOptions.Add(optionsTextCHB);
listOptions.Add(optionsTextDIG);
// sign document to file
signature.Sign("signedSample.pdf", listOptions);
}
Sign PDF document with Combobox Form Field signature
This example shows how to add combo box Form Field signature to PDF document. See SignResult
// initialize Signature instance
using (Signature signature = new Signature(filePath))
{
// instantiate combo box form field signature
List<string> items = new List<string>() { "Red", "Green", "Blue" };
ComboboxFormFieldSignature combobox = new ComboboxFormFieldSignature("combo1", items, "Blue");
// instantiate options based on text form field signature
FormFieldSignOptions options = new FormFieldSignOptions(combobox)
{
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Padding(0, 0, 0, 0),
Height = 100,
Width = 300,
};
// sign document to file
SignResult signResult = signature.Sign("sampleSigned.pdf", options);
}
Sign PDF document with Radio buttons Form Field signature
This example shows how to add radio buttons Form Field signature to PDF document. See SignResult
// initialize Signature instance
using (Signature signature = new Signature(filePath))
{
// instantiate radio-button form field signature
List<string> radioOptions = new List<string>() { "One", "Two", "Three" };
RadioButtonFormFieldSignature radioSignature = new RadioButtonFormFieldSignature("radioData1", radioOptions, "Two");
// instantiate options based on text form field signature
FormFieldSignOptions options = new FormFieldSignOptions(radioSignature)
{
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Padding(0, 0, 0, 0),
Height = 100,
Width = 300,
};
// sign document to file
SignResult signResult = signature.Sign("sampleSigned.pdf", options );
}
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.