Convert MS Word DOCX to PDF with Form Fields in C# .NET: Preserve or Flatten Form Fields
TX Text Control converts DOCX to PDF while preserving or flattening form fields, ensuring accurate import and export. Its flexible API simplifies form field handling for seamless document processing.

TX Text Control makes it easy to convert Microsoft Word DOCX documents to PDF, including embedded form fields. Whether your DOCX files contain legacy form fields or content controls, TX Text Control ensures that they are accurately preserved in the exported PDF, either as interactive AcroForms or as a flattened, non-editable form.
MS Word Form Fields
There are two types of form fields in MS Word. Legacy form fields, as the name suggests, are from older versions such as MS Word 97, but remain compatible with newer versions. Content Control Form Fields, on the other hand, represent the modern approach to form fields in MS Word. When you load the RTF, DOC, or DOCX (Office Open XML) document types, both can be imported into the TX Text control.
When loading a document, the Application
- None
Text fields supported by other applications are not imported as ApplicationFields . Instead, form fields are imported as TX Text Control FormFields . - MSWord
Fields that are supported and defined by Microsoft Word are imported as ApplicationFields . The ApplicationField property allows you to specify which field types to import.Type Names - MSWordTXFormFields
Fields supported and defined by Microsoft Word are imported asApplicationFields , except for form fields. Form fields, including combo boxes, check boxes, and form text fields, are imported as TX Text Control FormFields .
To load both form fields from MS Word documents, you can use the MSWordTXFormFields setting. The following screenshot shows a sample document with form fields in MS Word:

Importing Form Fields
The following code demonstrates how to load a document with legacy and content control form fields that are automatically converted to form fields.
using TXTextControl;
TXTextControl.LoadSettings loadSettings = new TXTextControl.LoadSettings()
{
ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWordTXFormFields
};
using (TXTextControl.ServerTextControl serverTextControl =
new TXTextControl.ServerTextControl())
{
serverTextControl.Create();
serverTextControl.Load("forms.docx",
TXTextControl.StreamType.WordprocessingML, loadSettings);
foreach (FormField ff in serverTextControl.FormFields)
{
Console.WriteLine(ff.Text);
}
}
Exporting Form Fields to PDF
Now we can export this document as is to PDF, which will export all the form types it contains to AcroForms. The following code shows how to call the Save method after importing the DOCX document.
using TXTextControl;
TXTextControl.LoadSettings loadSettings = new TXTextControl.LoadSettings()
{
ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWordTXFormFields
};
using (TXTextControl.ServerTextControl serverTextControl =
new TXTextControl.ServerTextControl())
{
serverTextControl.Create();
serverTextControl.Load("forms.docx",
TXTextControl.StreamType.WordprocessingML, loadSettings);
serverTextControl.Save("forms.pdf", TXTextControl.StreamType.AdobePDF);
}
The resulting PDF document contains the form fields as interactive AcroForms. The following screenshot shows the exported PDF document with the form fields:

Flattening Form Fields
When a document is finalized for export and sharing as a PDF, form fields are typically flattened. This process converts the form fields into static text, preventing users from making further changes. TX Text Control provides an overload of the Form
using TXTextControl;
public static class FormFieldExtender
{
public static void Flatten(this FormFieldCollection formFields, FormField formField)
{
formFields.Remove(formField, true);
}
public static void Flatten(this FormFieldCollection formFields)
{
int fieldCount = formFields.Count;
for (int i = 0; i < fieldCount; i++)
{
TextFieldCollectionBase.TextFieldEnumerator fieldEnum =
formFields.GetEnumerator();
fieldEnum.MoveNext();
FormField curField = (FormField)fieldEnum.Current;
formFields.Remove(curField, true);
}
}
}
The complete code would look like this, along with the loading code above:
using TXTextControl;
TXTextControl.LoadSettings loadSettings = new TXTextControl.LoadSettings()
{
ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWordTXFormFields
};
using (TXTextControl.ServerTextControl serverTextControl =
new TXTextControl.ServerTextControl())
{
serverTextControl.Create();
serverTextControl.Load("forms.docx",
TXTextControl.StreamType.WordprocessingML, loadSettings);
// Flatten all form fields
serverTextControl.FormFields.Flatten();
// Save the document as PDF
serverTextControl.Save("forms.pdf", TXTextControl.StreamType.AdobePDF);
}
The resulting PDF document contains the form fields as flattened text. The following screenshot shows the exported PDF document with the form fields flattened:

Conclusion
TX Text Control provides a powerful API to importing and exporting form fields from MS Word documents. The Application
ASP.NET
Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.
- Angular
- Blazor
- React
- JavaScript
- ASP.NET MVC, ASP.NET Core, and WebForms
Related Posts
Streamline Data Collection with Embedded Forms in C# .NET
Discover how to enhance your C# .NET applications by embedding forms for data collection. This article explores the benefits of using Text Control's ASP.NET and ASP.NET Core components to create…
Export and Import Adobe PDF XFDF XML Files in .NET C#
This article shows how to export and import Adobe PDF XFDF XML files in .NET C# using the TX Text Control .NET Server component. Form fields from PDF documents are exported to XFDF XML files and…
Automating PDF/UA Accessibility with AI: Describing DOCX Documents Using TX…
This article shows how to use TX Text Control together with the OpenAI API to automatically add descriptive texts (alt text and labels) to images, links, and tables in a DOCX. The resulting…
Converting Office Open XML (DOCX) to PDF in Java
Learn how to convert Office Open XML (DOCX) documents to PDF in Java using the powerful ServerTextControl library. This guide provides step-by-step instructions and code examples to help you…
Extending DS Server with Custom Digital Signature APIs
In this article, we will explore how to extend the functionality of DS Server by integrating custom digital signature APIs. We will cover the necessary steps to create a plugin that allows DS…
