Documents with form elements such as form text boxes, check box fields, drop-downs and date picker elements can be created like mail merge templates and dynamically pre-completed with known values. This helps to generate custom forms where some fields are already completed with known values to accelerate the completion process and to improve the user experience.

Sample Database

The sample uses a simple, serverless NoSQL database (LiteDB) to store customer address data. The Customer model is defined through the following code:

Loading...

The sample view is a very simple table that lists all customers from the database:

Selecting the user

The template contains some form text fields, drop-downs, a date picker element and a check box to cover all available form field elements. The form field names match the property names in the Customer data model.

Sample template

When clicking the button Download Form, the sample template is loaded into a ServerTextControl TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
ServerTextControl Class
The ServerTextControl class implements a component that provide high-level text processing features for server-based applications.
instance in order to loop through all form fields in each text part (headers, footers, main text, text frames).

Loading...

Generic Function to Merge the Data

The customer address record with the given Id is retrieved from the database and used to populate the existing form fields. The interesting code line is the following line:

Loading...

This code is trying to read a property from the Customer object with the form field name. This makes this code very generic as the values are then casted to the proper type and applied to the appropriate property ( Text TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
TextField Class
Text Property
Returns or sets the text which is contained within a text field.
, Checked TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
CheckFormField Class
Checked Property
Gets or set a value indicating whether the checkbox is in the checked state.
, Date TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
DateFormField Class
Date Property
Gets or sets the DateFormField's date.
).

After all available fields have been merged, the document is exported to PDF and returned as an attachment for download:

Sample template

You can download the sample from our GitHub repository to try this on your own. Let us know, if you have any questions about how to integrate document workflows into your business applications.