Apply Digital Signatures to PDF Signature Fields Imported from MS Word in C#
Signature fields can be created and imported from MS Word documents such as DOCX. They can be processed by TX Text Control and applied to a PDF document. The necessary steps are explained in this article.

TX Text Control provides all of the parts and processes needed to implement electronic (digital) signatures on PDF documents. From the dynamic creation of templates with signature fields, to the collection of signatures from end users, to the digital signing of PDF documents.
Creating Signature Lines in MS Word
The TX Text Control Signature
Additional information can be added to the signature line in the opened dialog.
The created signature line will look like the one shown in the following screenshot.
Adding Additional Information
When signing PDF documents, TX Text Control provides additional Signer
Property | Description |
---|---|
Address | Gets the address of a suggested signer. |
ContactInfo | Gets contact information of a suggested signer, such as a phone number. |
Name | Gets the name of a suggested signer. |
Reason | Gets a reason why the document is signed. |
Title | Gets the title of a suggested signer. |
The following code shows how to load the Office Open XML MS Word document and add additional properties to the SignerData.
using (TXTextControl.ServerTextControl tx = new ServerTextControl())
{
tx.Create();
tx.Load("template.docx", TXTextControl.StreamType.WordprocessingML);
foreach (SignatureField field in tx.SignatureFields)
{
var signerData = field.SignerData;
field.SignerData = new SignerData(field.SignerData.Name,
field.SignerData.Title,
"Test",
field.SignerData.ContactInfo,
"Contract verification");
}
tx.Save("template_changed.tx", TXTextControl.StreamType.InternalUnicodeFormat);
}
Acquiring the Signature
The Document Viewer is used to capture the user's electronic signature. The following code combines the setting of additional signer data and adds the signature fields to the active signature fields of the Document Viewer. In order to make the code readable for this article, everything will be placed in Razor code.
@using TXTextControl.Web.MVC.DocumentViewer
@{
byte[] documentArray;
List<SignatureBox> signatureBoxes = new List<SignatureBox>();
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
{
tx.Create();
tx.Load("App_Data\\template.docx", TXTextControl.StreamType.WordprocessingML);
// loop through all signature fields and set the signer data
foreach (TXTextControl.SignatureField field in tx.SignatureFields)
{
var signerData = field.SignerData;
field.SignerData = new TXTextControl.SignerData(field.SignerData.Name,
field.SignerData.Title,
"Test",
field.SignerData.ContactInfo,
"Contract verification");
// add a signature box to the document viewer
signatureBoxes.Add(new SignatureBox(field.Name) { SigningRequired = true, Style = SignatureBox.SignatureBoxStyle.Signature });
}
// save the document
tx.Save(out documentArray, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
}
}
@Html.TXTextControl().DocumentViewer(settings => {
settings.DocumentData = Convert.ToBase64String(documentArray);
settings.SignatureSettings = new SignatureSettings() {
ShowSignatureBar = true,
OwnerName = "Josh Jackson",
SignerName = "Tim Typer",
SignerInitials = "TT",
UniqueId = "12345-12345-12345-12345",
RedirectUrlAfterSignature = this.Url.Action(
"HandleSignature",
"Signature",
null,
Context.Request.Scheme,
null),
SignatureBoxes = signatureBoxes.ToArray()
};
}).Render()
The included signature field is converted into a signature box for the user to sign the document.
Signing Signature Fields
After the user has signed the document, the electronic signature is attached to the document and forwarded to the specified URL, along with the signature data, such as the signature image and the time stamp information.
Learn More
Capturing electronic signatures and signing signature fields with certificates is a common feature of the TX Text Control Document Viewer. The most common server-side Web API methods for handling electronic signatures are described in this article.
Common Web API Methods for Handling E-Signature Workflows in ASP.NET Core C#
The following HttpPost method loads the signed document and applies a certificate to each of the signature fields by going through the Signature
[HttpPost]
public IActionResult HandleSignature([FromBody] SignatureData data) {
byte[] bPDF;
// create temporary ServerTextControl
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
tx.Create();
// load the document
tx.Load(Convert.FromBase64String(data.SignedDocument.Document),
TXTextControl.BinaryStreamType.InternalUnicodeFormat);
X509Certificate2 cert = new X509Certificate2("App_Data/textcontrolself.pfx", "123");
var signatureFields = new List<DigitalSignature>();
foreach (SignatureBox box in data.SignatureBoxes) {
signatureFields.Add(new DigitalSignature(cert, null, box.Name));
}
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings() {
CreatorApplication = "Your Application",
SignatureFields = signatureFields.ToArray()
};
// store the PDF in the database or send it to the client
tx.Save(out bPDF, TXTextControl.BinaryStreamType.AdobePDFA, saveSettings);
// alternatively, save the PDF to a file
tx.Save("App_Data/signed.pdf", TXTextControl.StreamType.AdobePDFA, saveSettings);
}
// return any value to the client
return Ok();
}
All signature fields are digitally signed as a result of this implementation. The following screenshot shows the PDF file as it opens in Adobe Acrobat Reader and shows the valid signature field with the properties of the custom signer data. The created version of the document carries a digital signature that verifies that no tampering occurred after the document was created.
Related Posts
Sign Documents with a Self-Signed Digital ID From Adobe Acrobat Reader in…
This article shows how to create a self-signed digital ID using Adobe Acrobat Reader and how to use it to sign documents in .NET C#. The article also shows how to create a PDF document with a…
ASP.NETASP.NET CoreDocument Viewer
Getting Started Video Tutorial: How to Add Electronic and Digital Signatures…
This tutorial shows how to use the Document Viewer to electronically sign a document and how to implement an endpoint to add a digital certificate to the signature fields before exporting the…
ASP.NETASP.NET CoreDocument Viewer
Transforming Financial Documents into Smart and Secure Forms in ASP.NET Core C#
This article shows how to transform financial documents into smart and secure forms in ASP.NET Core C#. All the necessary steps, from prepopulating the form fields to digital signatures, are…
AngularASP.NET CoreDigital Signature
How to Add Electronic and Digital Signatures to PDFs in ASP.NET Core C# and…
Learn how to add electronic and digital signatures to PDFs in ASP.NET Core C# and Angular. This tutorial shows how to create an Angular application with an ASP.NET Core backend that uses the…
ASP.NETASP.NET CoreDocument Viewer
High-Performance Text Replacement in Large DOCX Files using C# .NET
Learn how to efficiently replace text in large DOCX files using C# .NET and the ServerTextControl component from Text Control. This article demonstrates the performance benefits of using the…