TX Text Control provides a powerful API to sign PDF documents with signature fields and digital signatures. This article shows how to sign a PDF document with a digital signature using the TX Text Control API and to set custom signer information.
Pre-Populated Signer Information
Signer information, such as the reason for signing and the signer's address, can be added at the design time of the document or template. This information is stored in the internal TX Text Control document format and can be used to pre-fill the signature fields.
The following screenshots show a signature field and the ribbon bar with the pre-populated information:
When signing the document with a digital signature, the pre-populated information is used automatically.
Custom Signer Information
When signing a document with a digital signature, the signer information can be set programmatically using the Signer ╰ TX Text Control .NET Server for ASP.NET
╰ TXTextControl Namespace
╰ SignatureField Class
╰ SignerData Property
Gets or sets a suggested signer's name, title and address and a reason why to sign the document. property. This property is an instance of the Signer ╰ TX Text Control .NET Server for ASP.NET
╰ TXTextControl Namespace
╰ SignerData Class
An instance of the SignerData class represents the data of a suggested signer connected with a SignatureField. class that provides the following properties:
Property | Description |
---|---|
Reason |
Gets or sets the reason for signing the document. |
Address |
Gets or sets the location of the signer. |
ContactInfo |
Gets or sets the contact information of the signer. |
Name |
Gets or sets the name of the signer. |
Title |
Gets or sets the title of the signer. |
The following code snippet shows how to set the signer information for a signature field:
using System.Security.Cryptography.X509Certificates; | |
using TXTextControl; | |
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) | |
{ | |
tx.Create(); | |
tx.Load("signature.tx", TXTextControl.StreamType.InternalUnicodeFormat); | |
// create a certificate | |
X509Certificate2 cert = new X509Certificate2("textcontrolself.pfx", "123"); | |
// create a list of digital signatures | |
var digitalSignatures = new List<DigitalSignature>(); | |
foreach (SignatureField signatureField in tx.SignatureFields) | |
{ | |
signatureField.SignerData = new SignerData( | |
"John Doe", | |
"CEO", | |
"11 Main Street, New York, NY 10001, USA", | |
"john@doe.com", | |
"Contract signature"); | |
// time stamp server | |
var timeStampServer = "http://timestamp.digicert.com"; | |
// create a digital signature object | |
DigitalSignature digitalSignature = new DigitalSignature(cert, timeStampServer, signatureField.Name); | |
// add the digital signature to the list | |
digitalSignatures.Add(digitalSignature); | |
} | |
// create save settings | |
SaveSettings saveSettings = new SaveSettings() | |
{ | |
CreatorApplication = "Your Application", | |
SignatureFields = digitalSignatures.ToArray() | |
}; | |
// save the document as PDF | |
tx.Save("results_signed.pdf", StreamType.AdobePDFA, saveSettings); | |
} |
Additionally, the time server is added to the digital signature. The timeServerURL parameter is set to the URL of the time server.
When the document is signed, the signature field is updated with the custom signer information:
When the document is opened in Adobe Acrobat Reader, the custom signer information is displayed in the signature properties.
Conclusion
TX Text Control provides a powerful API to sign PDF documents with signature fields and digital signatures. The signer information can be pre-populated at the design time of the document or set programmatically using the SignerData property.