ImageGear .NET v25.1 - Updated
Flatten Form Fields
User Guide > How to Work with... > PDF > How to... > Work with PDF Forms > Flatten Form Fields
ImageGear for .NET does not support modification of forms in PDF documents containing XFA. Please see XFA Support for more information.

Flattening form fields refers to the process of converting user-interactive form fields into static page content. After flattening a field, the interactive representation is removed from the document.

The FlattenFormField call flattens the specified field into the page, while FlattenFormFields repeats this process for each field in the PDF.

Each method accepts a boolean indicating whether only fields that are set to appear during printing should be flattened, while the others are removed. This is particularly useful for interactive fields like buttons, that make no sense on a printed piece of paper. See the FlattenFormField and FlattenFormsFields pages for more information on the parameters.

The following code shows examples of how to flatten form fields:

PDF support needs to be initialized first for this snippet to work. To get familiar with initializing IGNET, initializing PDF support, loading a PDF, saving a PDF, and terminating PDF support, try any one of the tutorials.
C#
Copy Code
using ImageGear.Formats.PDF;
using ImageGear.Formats.PDF.Forms;

void FlattenFormFields(ImGearPDFDocument document, string fieldName)
{
    // Find and remove a single field.
    Field field = document.Form.Fields[fieldName];
    document.FlattenFormField(field, false);

    // Flatten all fields.
    document.FlattenFormFields(false);
}
VB.NET
Copy Code
Imports ImageGear.Formats.PDF
Imports ImageGear.Formats.PDF.Forms

Private Sub FlattenFormFields(ByVal document As ImGearPDFDocument, ByVal fieldName As String)
    // Find and remove a single field.
    Dim field As Field = document.Form.Fields(fieldName)
    document.FlattenFormField(field, False)

    // Find and remove a single field.
    document.FlattenFormFields(False)
End Sub

Flattening Notes