ImageGear v26.3 - Updated
Developer Guide / How to Work with ... / PDF / How to... / Work with PDF Forms / Flatten Form Fields
In This Topic
    Flatten Form Fields
    In This Topic

    ImageGear 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.

    C#

    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

    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

    • The visibility of each of the field depends on whether the HIDDEN, PRINT or NOVIEW flags are set in the field’s widget annotations. These will be respected during flattening.
      • An annotation with a HIDDEN flag will never appear on the page.
      • An annotation with a NOVIEW flag will appear on the page only if "forPrinter" is specified in the flatten method calls.
      • An annotation without a PRINT flag will appear on the page only if "forPrinter" is not specified.
    • Flattening a signature field removes all visual information.
    • FlattenFormFields also removes any XFA data, if present. The use of FlattenFormField is not supported on documents containing XFA and may lead to inconsistencies in the document. See XFA Support for more information.