Skip to main content
A newer version of this page is available. .

Flatten Interactive Forms

  • 2 minutes to read

This document explains interactive form flattening and provides information on how to flatten interactive forms using the PDF Document API component.

This document consists of the following sections.

Overview

A PDF document can contain interactive forms (AcroForms) with form fields (e.g., text fields, buttons, list boxes). You can edit an interactive form (e.g., click on the form field and change its value, or fill it out).

FormBeforeFlattening

For more information about filling a form with data, see the How to: Fill an Interactive Form with Values example.

The PDF Document API component can flatten these form fields. The flattening process removes the form field interactive features, so the value entered or selected in the form field will be rendered like regular content (e.g., text, images, shapes, and so on).

FormAfterFlattening

Note

The flattening process cannot be undone, so it is recommended that you save the flattened document under a different name.

You can flatten interactive forms in two ways.

  • Flattening an entire form
  • Flattening a form field by its name

The sections below detail each approach to flattening.

Flatten an Entire Form

To flatten an entire form, call the PdfDocumentProcessor.FlattenForm method. This method returns false if the document does not contain an interactive form to be flattened, otherwise it returns – true.

See the code snippet below.


using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
     processor.LoadDocument("FormDemo.pdf");
     if (processor.FlattenForm())
          processor.SaveDocument("Result.pdf");
}

Tip

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T446039.

Flatten a Specific Field by its Name

If you need to flatten specific fields, you can call the PdfDocumentProcessor.FlattenFormField method and pass the name of the field to it. This method returns false, if the form field was not found in the document; otherwise it returns - true.

Note that the PdfDocumentProcessor.FlattenFormField method flattens only a field whose name is known. Other form fields maintain their interactive features.

To obtain a list of form fields names, use the PdfDocumentProcessor.GetFormFieldNames method.