New MailMerge Live Demo: Form Field Mail Merge
To increase the user experience, to accelerate the process and to decrease errors, parts of a document can be pre-populated. The MailMerge class can be used to merge data into form fields.

The Mail
We just published a new online demo that shows how to implement these options based on a typical form used in the healthcare industry.
Pre-Selecting Form Fields
On the first button click, the form fields are pre-selected with existing JSON data. To increase the user experience, to accelerate the process and to decrease errors, parts of a document can be pre-populated with known values.
The HttpGet controller method PDFPrepare is called with the boolean flatten parameter false.
[HttpGet]
public string PDFPrepare(bool flatten) {
byte[] bDocument;
// create temporary ServerTextControl
using (ServerTextControl tx = new ServerTextControl()) {
tx.Create();
// loading the template
tx.Load(Server.MapPath("~/App_Data/Documents/patient_history.tx"), StreamType.InternalUnicodeFormat);
// fire up the MailMerge engine
using (MailMerge mailMerge = new MailMerge()) {
mailMerge.TextComponent = tx; // connect to ServerTextControl
// pre-selecting form fields
if (flatten == false)
mailMerge.FormFieldMergeType = FormFieldMergeType.Preselect;
else // flatten form fields
mailMerge.FormFieldMergeType = FormFieldMergeType.Replace;
string jsonData = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/Documents/data.json"));
// merge JSON into fields
mailMerge.MergeJsonData(jsonData);
}
// export to PDF
tx.Save(out bDocument, BinaryStreamType.InternalUnicodeFormat);
}
// return as Base64 encoded string
return Convert.ToBase64String(bDocument);
}
In this case, the Form
Flattening Form Fields
On the second button, the controller method PDFPrepare is called with the boolean flatten parameter true. The Form
Live Demo
Test this demo live in our online demos.
Related Posts
When to Generate Documents Server-Side Instead of Client-Side: A Focus on…
When it comes to document generation, deciding whether to handle the task server-side or client-side is a key architectural decision for any organization. This article discusses the benefits of…
Getting Started Video Tutorial: How to use the MailMerge and…
This video tutorial shows how to use the MailMerge and ServerTextControl classes in an ASP.NET Core application using C#. This tutorial is part of the TX Text Control Getting Started series…
ASP.NETASP.NET CoreGetting Started Video
Getting Started Videos: New Text Control YouTube Channel
We just launched a new YouTube channel that is dedicated to getting started videos. The first videos show how to use the Document Editor, Document Viewer, and MailMerge components in ASP.NET Core…
ASP.NETMailMergeServerTextControl
Creating Valid XRechnung / ZUGFeRD Invoices with ASP.NET Core C#
This article shows how to create valid XRechnung and ZUGFeRD invoices with ASP.NET Core C#. The invoice is created with the help MailMerge component and the ZUGFeRD-csharp library.
Use Case: Blood Pressure Report with Charts in C#
Providing human-readable reports in healthcare is an important part of improving transparency and patient satisfaction. This sample template shows how to visualize a series of blood pressure…