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 is usually used to merge objects or JSON data into document templates to populate merge fields. Since version 30.0, the MailMerge class can be used to merge data into form fields as well.

Merging Form Fields

The FormFieldMergeType TX Text Control .NET Server for ASP.NET
DocumentServer Namespace
MailMerge Class
FormFieldMergeType Property
Specifies in which manner form fields are treated during the merge process.
defines how form fields are treated during the merge process.

Member Description
None Form fields are not merged at all.
Preselect Form field content is preselected when possible. Form fields not associated with a data table column are unaffected.
Replace Form fields are replaced with database content. Empty form fields are removed according to property RemoveEmptyFields TX Text Control .NET Server for ASP.NET
DocumentServer Namespace
MailMerge Class
RemoveEmptyFields Property
Specifies whether empty fields should be removed from the template or not.
property.

Consider the following sample template that contains different form fields including checkboxes, drop-downs and form text fields:

Form Template

Pre-Populate Form Fields

The MailMerge class can now be used for 2 different scenarios. In the first scenario, the form should be pre-populated with known data to help users by minimizing their efforts to complete the form. The following code shows how to load the template into a ServerTextControl instance to merge it using the MailMerge engine:

Loading...

The following screenshot shows the PDF document in Acrobat Reader. The form fields are pre-populated with the merged data:

Form Template

Flatten Form Fields

In the second scenario, the document should be flattened by removing all form fields and replacing them with the actual merge data:

Loading...

In the resulting document, all form fields are removed and the document is not an editable form document anymore:

Form Template

The MailMerge class can be used to merge both merge fields and form fields in the same merge process. This helps to generate forms with dynamic, non-editable data (merge fields) and pre-populated form fields that can be edited by end-users. Pre-populating fields in a form eliminates errors, increases the user acceptance and provides a better user experience.