TX Text Control provides a comprehensive way to create documents with fillable form elements such as form text boxes, check box fields and drop-down elements. 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.

Using TX Text Control, PDF documents can be easily created, shared and collected in business applications. PDF forms with fillable form elements can be created and collected by reading the completed documents in order to analyze and store the data.

Creating the PDF Programmatically

This article shows how to create a PDF document with AcroForms that can be completed in document viewers such as Adobe Acrobat Reader. At least a trial version of TX Text Control .NET Server for ASP.NET is required for this tutorial.

  1. In Visual Studio, create a new C# Console App (.NET Framework).

    Creating forms

  2. Select Add Reference... from the Project main menu. In the opened dialog, choose Browse... and browse for the TX Text Control assemblies TXTextControl.dll and TXTextControl.Server.dll from the TX Text Control installation folder (default: C:\Program Files\Text Control GmbH\TX Text Control 29.0.NET Server for ASP.NET\Assembly). Select both assemblies and confirm with Add. Close the dialog by clicking OK.

  3. In the Solution Explorer, select Properties and choose Add New Item... from the Project main menu. Select Text File as the template, name it licenses.licx and confirm with Add.

  4. Open the newly added file and add the following content:

    TXTextControl.ServerTextControl, TXTextControl.Server, Culture=neutral, PublicKeyToken=6b83fe9a75cfb638

    Set the Build Action property to Embedded Resource.

  5. Add the following code to the Main method of the Program class to create a PDF with form fields programmatically from scratch:

    using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
    tx.Create();
    tx.Selection.FontSize = 800;
    tx.Selection.Text = "Sample Form\r\n\r\n";
    tx.Selection.FontSize = 400;
    tx.Selection.Text = "Company name:\r\n";
    // add a text form field
    TXTextControl.TextFormField textFormField = new TXTextControl.TextFormField(1000);
    textFormField.Name = "company_name";
    textFormField.Text = "Text Control, LLC";
    tx.FormFields.Add(textFormField);
    tx.Selection.Text = "\r\n\r\nCountry:\r\n";
    // add a text form field
    TXTextControl.SelectionFormField selectionFormField = new TXTextControl.SelectionFormField(1000);
    selectionFormField.Name = "company_country";
    selectionFormField.Items = new string[] { "United States", "Germany", "Italy" };
    selectionFormField.SelectedIndex = 0;
    tx.FormFields.Add(selectionFormField);
    // export the document as PDF
    tx.Save("results.pdf", TXTextControl.StreamType.AdobePDF);
    }
    view raw sample.cs hosted with ❤ by GitHub

After loading this document in Adobe Acrobat Reader, the document is recognized automatically as a form and users can complete the fields.

Creating forms

Creating Forms Visually

An easier way to create those documents is the usage of templates. Using the fully-featured UI of all TX Text Control platform products including ASP.NET (Core), Angular, Windows Forms and WPF, the documents can be visually created including the required form fields:

Creating forms