Companies and organizations in every industry are recognizing the value of integrating electronic signatures into their workflows. Many e-signature services start the signature process with a pre-generated PDF document that comes from applications such as MS Word or ERP systems.

Dynamic Templates

However, a document should be able to be edited for as long as possible. It is a dynamic structure that should be able to be updated at any time until the process is complete and a document is created for further processing or archiving.

MS Word Compatible

Instead of a sealed PDF document, the document signing process starts with an MS Word compatible template. This gives developers the flexibility they need to integrate the entire pipeline of digital document processing into their own workflows. Typically, the signature process starts with a template consisting of merge field placeholders and form fields that are pre-populated before the generated document is passed to the signature workflow.

A simple template consisting of a standard layout, static data, dynamic merge, and form fields is shown in the following screenshot:

Creating documents with TX Text Control

Pre-Populate Fields

Before you use the Document Viewer to deliver this document to the end user, you can prepare it by merging the data you know into the document. The following code uses the MailMerge TX Text Control .NET Server for ASP.NET
DocumentServer Namespace
MailMerge Class
The MailMerge class is a .NET component that can be used to effortlessly merge template documents with database content in .NET projects, such as ASP.NET web applications, web services or Windows services.
class to merge a data object into the template.

byte[] document;
using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
tx.Create();
tx.Load("App_Data/vaccination_form.tx", TXTextControl.StreamType.InternalUnicodeFormat);
using (TXTextControl.DocumentServer.MailMerge mm =
new TXTextControl.DocumentServer.MailMerge()) {
mm.TextComponent = tx;
mm.FormFieldMergeType = TXTextControl.DocumentServer.FormFieldMergeType.Preselect;
mm.RemoveEmptyFields = false;
// pre-select form fields with known data and merge
// data into merge fields
mm.MergeObject(data);
}
tx.Save(out document, TXTextControl.BinaryStreamType.InternalUnicodeFormat);
}
view raw test.cs hosted with ❤ by GitHub

Capturing Signatures

The pre-populated document is then loaded into the Document Viewer to capture user data and the final signature.

Creating documents with TX Text Control

Digital Signing

When the document is submitted, the Document Viewer automatically merges the completed form field values and captured signature into the document. Finally, server-side certificate signing is performed to retrieve a fully digitally signed and tamper-proofed PDF document.

[HttpPost]
public string ExportPDF()
{
Stream inputStream = Request.InputStream;
inputStream.Position = 0;
StreamReader str = new StreamReader(inputStream);
string sBuf = str.ReadToEndAsync().Result;
TXTextControl.Web.MVC.DocumentViewer.Models.SignatureData data =
JsonConvert.DeserializeObject<TXTextControl.Web.MVC.DocumentViewer.Models.SignatureData>(sBuf);
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);
FlattenFormFields(tx);
X509Certificate2 cert = new X509Certificate2(Server.MapPath("~/App_Data/textcontrolself.pfx"), "123");
TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings()
{
CreatorApplication = "TX Text Control Sample Application",
//DigitalSignature = new TXTextControl.DigitalSignature(cert, null),
SignatureFields = new DigitalSignature[] {
new TXTextControl.DigitalSignature(cert, null, "txsign"),
new TXTextControl.DigitalSignature(cert, null, "txsign_init")}
};
// save the document as PDF
tx.Save(out bPDF, TXTextControl.BinaryStreamType.AdobePDFA, saveSettings);
}
// return as Base64 encoded string
return Convert.ToBase64String(bPDF);
}
view raw test.cs hosted with ❤ by GitHub

When you open the generated document, you can see the validity of the signature fields in the Acrobat Reader.

Creating documents with TX Text Control