What is PDF form flattening?

PDF files can include interactive forms – radio buttons, checkboxes, text boxes, lists, etc. There are interactive widgets – the user can click on the and change the values. So you can use PDF files for everything from your tax returns to ordering pizza.

The data for forms is stored in a separate area to the text on the page (which coincidentally makes it much easier to edit and extract). Forms flattening is the process of removing this separate form data and adding it as text, images and shapes into the actual PDF data stream. The PDF will still look the same but the user can no longer interact with the forms.

There are several good reasons for doing this:-

1. It stops the form values being editable and easily changed.

2. It removes the other values on lists and drop down boxes.

3. It simplifies the PDF (and will generally make it faster to render).

The one disadvantage is that it makes it much harder to extract or alter the form data – that checkbox is now just a special character on the page. So keep the originals just incase.

This post is part of our “Understanding the PDF File Format” series. In each article, we discuss a PDF feature, bug, gotcha or tip. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.
He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.
He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.