# Exporting Interactive and Flattened Forms

> Save PDF forms fillable with access permissions or flattened in Windows Forms: GetTextFields and Clear, flatten single fields, and FormFieldMergeType.Replace.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > PDF Processing > PDF Forms > Exporting Interactive and Flattened Forms
- **2921 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/pdf/forms/exporting/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/pdf/forms/exporting/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/pdf/forms/exporting/llms-full.txt

---

The same form leaves a Windows Forms application in one of two states. Sent to a customer, it stays *interactive*: the PDF has fields that the customer fills in. Signed, approved or archived, it is *flattened*: each form field is replaced by the text it shows, so nobody can change the values in a PDF reader. You choose the state when you save, for all fields or only some of them.

The examples use the form of [Create a PDF Form](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/pdf/form/llms-full.txt), with the form fields `name`, `country` and `newsletter`, in `textControl1`.

### Interactive or Flattened

|  | Interactive form | Flattened form |
|---|---|---|
| In the PDF | AcroForm fields with names and values | Text, check box characters and dates at the places of the fields |
| Users can | Fill in and change the values in a PDF reader | Read and print the document |
| Your code can | Read the values with `Forms.GetAcroFormFields` | Only extract text, as [Text Extraction](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/pdf/text-extraction/llms-full.txt) describes |
| Typical use | Forms sent out to be filled in | Confirmations, contracts and archived forms |

A flattened form field is removed from the document, and the text it showed stays in its place:

| Form field | Text that remains |
|---|---|
| [TextFormField](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textformfield/llms-full.txt) | The entered text |
| [SelectionFormField](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/selectionformfield/llms-full.txt) | The text of the selected item |
| [DateFormField](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/dateformfield/llms-full.txt) | The date as the field displays it, formatted with its [DateFormat](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/dateformfield/dateformat-property/llms-full.txt) |
| [CheckFormField](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/checkformfield/llms-full.txt) | The character that shows the state of the check box, set with [CheckedCharacter](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/checkformfield/checkedcharacter-property/llms-full.txt) and [UncheckedCharacter](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/checkformfield/uncheckedcharacter-property/llms-full.txt) |

Read the values before you flatten, as [Reading Form Fields and Values](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/pdf/forms/reading-fields/llms-full.txt) describes. A [SignatureField](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/signaturefield/llms-full.txt) isn't a form field, so flattening leaves signature fields in place.

### Save a Fillable Form

Saved with `StreamType.AdobePDF`, form fields are always saved as fillable fields. A master password and permissions let readers fill in the form and print it, but not change the rest of the document:

```csharp
private void saveFillableFormButton_Click(object sender, EventArgs e)
{
    SaveSettings saveSettings = new SaveSettings()
    {
        MasterPassword = "owner1234",

        // Fill in the fields and print, nothing else
        DocumentAccessPermissions = DocumentAccessPermissions.AllowAuthoringFields |
                                    DocumentAccessPermissions.AllowHighLevelPrinting
    };

    textControl1.Save("form.pdf", StreamType.AdobePDF, saveSettings);
}
```

[DocumentAccessPermissions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/savesettings/documentaccesspermissions-property/llms-full.txt) `AllowAuthoringFields` allows filling in existing form fields, and `AllowHighLevelPrinting` allows printing. The permissions take effect only together with a [MasterPassword](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/loadsavesettingsbase/masterpassword-property/llms-full.txt). Without a user password, everyone can open the form. [Passwords and Access Permissions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/pdf/passwords/llms-full.txt) lists all permissions.

In Adobe Acrobat Reader, the fields of an interactive form are highlighted and can be filled in:

![A PDF form in Adobe Acrobat Reader with highlighted form fields: text fields, a check box and drop-down lists.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/pdf-form-fillable.09e3ba10.webp)

### Save a Flattened Copy

To send a flattened PDF while the user continues with the form in the editor, flatten a copy in a `ServerTextControl`:

```csharp
private void saveFlattenedFormButton_Click(object sender, EventArgs e)
{
    // A copy of the form in the editor, which keeps its form fields
    byte[] document;
    textControl1.Save(out document, BinaryStreamType.InternalUnicodeFormat);

    using (ServerTextControl tx = new ServerTextControl())
    {
        // Initialize the new instance before using it
        tx.Create();
        tx.Load(document, BinaryStreamType.InternalUnicodeFormat);

        // The main text, headers, footers and text frames
        foreach (IFormattedText textPart in tx.TextParts)
        {
            // true: the fields are removed, their text stays
            textPart.GetTextFields(TextFieldType.FormFields).Clear(true);
        }

        tx.Save("form-flattened.pdf", StreamType.AdobePDF);
    }
}
```

The code works as follows:

- [ServerTextControl.TextParts](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/servertextcontrol/textparts-property/llms-full.txt) contains the main text, the headers and footers and the text frames, so form fields in all of them are flattened.
- [IFormattedText.GetTextFields](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/iformattedtext/gettextfields-method/llms-full.txt) returns the fields of the [TextFieldType](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textfieldtype/enumeration/llms-full.txt) you pass as a [TextFieldCollection](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textfieldcollection/llms-full.txt). `FormFields` stands for all form field types, and the values can be combined, for example `TextFieldType.CheckFormField | TextFieldType.DateFormField`.
- [TextFieldCollection.Clear](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textfieldcollection/clear-method/llms-full.txt) with `true` removes the fields and keeps their text. [FormFieldCollection.Clear](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/formfieldcollection/clear-method/llms-full.txt) has no such parameter, so use `GetTextFields` for flattening.

The same form, flattened, shows its values as plain text:

![The same PDF form in Adobe Acrobat Reader after flattening: the values and check box characters are plain text without form fields.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/pdf-form-flattened.87fcff47.webp)

### Flatten Some Fields and Keep Others

A form can go out partly filled: the values your application knows are fixed, and the fields the recipient still has to fill in stay interactive. The following handler flattens every form field of `textControl1` except `newsletter`; it needs `using System.Collections.Generic;`:

```csharp
private void flattenSomeFieldsButton_Click(object sender, EventArgs e)
{
    foreach (IFormattedText textPart in textControl1.TextParts)
    {
        TextFieldCollection formFields = textPart.GetTextFields(TextFieldType.FormFields);

        // Collect first: removing a field changes the collection
        List<TextField> flatten = new List<TextField>();

        foreach (TextField field in formFields)
        {
            if (field.Name != "newsletter")
            {
                flatten.Add(field);
            }
        }

        foreach (TextField field in flatten)
        {
            formFields.Remove(field, true);
        }
    }

    textControl1.Save("form-partly-flattened.pdf", StreamType.AdobePDF);
}
```

[TextFieldCollection.Remove](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textfieldcollection/remove-method/llms-full.txt) with `true` as the second parameter removes a field and keeps its text; without it, the text is deleted as well. Here the fields are flattened in the editor itself, so the user sees the result. Reload the form to get the fields back.

### Flatten While Merging Data

When a form is final as soon as data is merged into it, [MailMerge.FormFieldMergeType](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/formfieldmergetype-property/llms-full.txt) `Replace` fills and flattens in one step:

```csharp
private void mergeAndFlattenButton_Click(object sender, EventArgs e)
{
    textControl1.Load("form.tx", StreamType.InternalUnicodeFormat);

    using (MailMerge mailMerge = new MailMerge()
    {
        TextComponent = textControl1,

        // Fill the form fields and replace them with their values
        FormFieldMergeType = FormFieldMergeType.Replace
    })
    {
        mailMerge.MergeJsonData(File.ReadAllText("registration.json"));
    }

    textControl1.Save("registration-final.pdf", StreamType.AdobePDF);
}
```

The handler needs `using TXTextControl.DocumentServer;`. With `Replace`, the form fields are replaced with the values of the data, and empty form fields are removed according to [RemoveEmptyFields](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-documentserver/mailmerge/removeemptyfields-property/llms-full.txt). `Preselect` fills the fields and keeps them interactive. [Merge Form Fields](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/mail-merge/fields/#merge-form-fields) compares the merge types.

### Flatten Before Signing and Archiving

- **Signing.** A digital signature covers the document as it is saved. Flatten first, then save with [SaveSettings.DigitalSignature](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/savesettings/digitalsignature-property/llms-full.txt), so that the signed PDF contains the final values, as [Signing PDF Documents](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/digital-signatures/signing/llms-full.txt) describes.
- **Archiving.** A flattened form saved with `StreamType.AdobePDFA` is a PDF/A document with fixed values, as [PDF/A](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/pdf/pdf-a/llms-full.txt) describes.

The blog article [Convert MS Word DOCX to PDF with Form Fields in C# .NET: Preserve or Flatten Form Fields](https://www.textcontrol.com/blog/2025/02/26/convert-ms-word-docx-to-pdf-with-form-fields-in-csharp-dotnet/) converts a Word form both ways.

### Next Steps

- [Reading Form Fields and Values](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/pdf/forms/reading-fields/llms-full.txt): read the values before you flatten.
- [PDF/A](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/pdf/pdf-a/llms-full.txt): archive flattened forms.
- [Digital Signatures](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/digital-signatures/llms-full.txt): sign the final document.

---

## Nearby

- **Previous:** [Reading Form Fields and Values](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/pdf/forms/reading-fields/llms-full.txt)
- **Next:** [Attachments](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/pdf/attachments/llms-full.txt)
