Creating Adobe PDF Forms in C#
Interactive forms in an Adobe PDF document can be used to gather information from end-users. This article shows how to create those forms using TX Text Control in .NET applications using C#.

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 is required for this tutorial.
-
In Visual Studio, create a new C# Console App (.NET Framework).
-
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.
-
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.
-
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.
-
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); }
After loading this document in Adobe Acrobat Reader, the document is recognized automatically as a form and users can complete the fields.
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:
Also See
This post references the following in the documentation:
- TXText
Control. Selection Form Field Class - TXText
Control. Server Text Control Class - TXText
Control. Server Text Control. Save Method - TXText
Control. Text Form Field Class
Angular
Integrate document processing, editing, sharing, collaboration, creation, electronic signatures, and PDF generation into your Angular Web applications.
Related Posts
AngularASP.NETDocument Processing
Creation of Custom Electronic Signature Boxes
This article describes the customization of electronic signature boxes. It contains further explanations including the creation of templates and shows all code snippets required. The step-by-step…
AngularASP.NETDocument Processing
Don't Print Your Documents! Streamlined Document Processes in Your Applications
In modern, collaborative environments, document review and approval processes can be streamlined by supporting the process with the right technology that helps to accelerate the workflows.
Importing Form Data from PDF Documents Exported from Chrome
Google Chrome 85 supports the completion and export of PDF documents with AcroForm form fields. When data is typed into these fields, the completed document can be exported.
Creating Advanced Tables in PDF and DOCX Documents with C#
This article shows how to create advanced tables in PDF and DOCX documents using the TX Text Control .NET for ASP.NET Server component. This article shows how to create tables from scratch,…
Form Field Compatibility: Work with AcroForms, Legacy MS Word Forms, and…
This article shows how to work with form fields in TX Text Control and how they are compatible with other industry standards. It explains how to load and save AcroForms, legacy MS Word forms and…