Products Technologies Demo Docs Blog Support Company

Importing and Processing Signature Fields from MS Word in C#

TX Text Control signature fields can be signed programmatically using a certificate. This article shows how to import signature fields from an existing MS Word document in order to sign them in a resulting PDF document.

Importing and Processing Signature Fields from MS Word in C#

The TX Text Control SignatureField objects are compatible to the Signature Line element in MS Word. This article shows how to insert those elements in MS Word in order to import and process these objects in TX Text Control.

Creating Signature Lines in MS Word

To create a document in MS Word that contains a signature line, use the Signature Line button in the Text ribbon group of the Insert ribbon tab.

Signature Line in MS Word

In the opened dialog, additional information can be added to the signature line. These values are available in the SignatureField class when importing the document into TX Text Control.

Signature Line in MS Word

After clicking OK, the signature line is inserted into the document.

Signature Line in MS Word

Processing SignatureFields

After loading the document into TX Text Control, the signature lines are accessible through the SignatureFieldCollection.

using (TXTextControl.ServerTextControl tx = new ServerTextControl()) {
  tx.Create();
  tx.Load("test.docx", TXTextControl.StreamType.WordprocessingML);

  foreach (SignatureField field in tx.SignatureFields) {
     Debug.WriteLine(JsonConvert.SerializeObject(field));
  }
}

All signature properties have been imported:

{
   "Image":null,
   "SignerData":{
      "Name":"Klaus Signer",
      "Title":"Chief Signer",
      "Address":"",
      "ContactInfo":"signer@klaus.com",
      "Reason":""
   }
}

TX Text Control provides additional SignerData properties to be compatible to the Adobe PDF format when signing PDF documents.

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.

Signing SignatureFields

An X509Certificate2 certificate object is created from a PFX file that is then assigned to all signature fields. The list of signatures is provided through the SignatureFields property to the Save method to export the signed document as an Adobe PDF document.

using (TXTextControl.ServerTextControl tx = new ServerTextControl()) {
  tx.Create();
  tx.Load("test.docx", TXTextControl.StreamType.WordprocessingML);

  List<TXTextControl.DigitalSignature> digitalSignatures = new List<DigitalSignature>();

  foreach (SignatureField field in tx.SignatureFields) {
     digitalSignatures.Add(new DigitalSignature(
     new System.Security.Cryptography.X509Certificates.X509Certificate2(
        "textcontrolself.pfx", "123"), null, field.Name));
  }

  SaveSettings saveSettings = new SaveSettings() {
     SignatureFields = digitalSignatures.ToArray()
  };

  tx.Save("results.pdf", TXTextControl.StreamType.AdobePDF, saveSettings);
}

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

ASP.NETASP.NET CoreDocument Editor

Preparing Documents for E-Signing for Multiple Signers in .NET C#

Learn how to prepare documents for e-signing by multiple signers in .NET C#. This article shows how to create signature fields and how to assign them to signers.


AngularASP.NETDocument Viewer

Customizing Electronic Signature Fonts for Typed Signatures in Angular and…

This article shows how to customize the electronic signature fonts for typed signatures in Angular and ASP.NET Core. It explains how to use custom fonts for the signature appearance and how to…


ASP.NETReleaseSignatures

Sneak Peek: Retrieving Timestamped Raw Signature Data

We are working on a feature for the Document Viewer that will return the raw signature data from the signature soft pad. This article will provide you with an overview of the functionality and the…


ASP.NETASP.NET CoreElectronic Signature

Customize Signature Fields with Dynamically Created SVG Images

Signature Fields signed using the Document Viewer can be completely customized with bitmap or vector images. This sample shows how to generate custom SVG images with signer information including…


ASP.NETAnnotationsDocumentViewer

DocumentViewer: Aspect Ratio Scaling of Signature Annotations

In the latest version of the DocumentViewer, signature annotations can be scaled by keeping the aspect ratio. This article gives a quick overview of signature annotations and this new feature.