PDF Document Processor: Interactive Forms Flattening (Coming soon in v16.2)

Paul Usher's Blog
31 October 2016

PDF documents have become one of the most widely used mediums for filling out forms. Combining elements such as text fields, drop down lists and buttons has made it simple for companies to provide a way to collect information. To ensure the integrity of the data a form can be ‘flattened’, this replaces the interactive fields with regular content such as text, images or shapes.


We are pleased to announce that starting with v16.2, the PDF Document Processor has the ability to perform field flattening.  You can achieve this in one of two ways:


•    Flatten entire form or;
•    Flatten a specific field on the form


To flatten the entire form, you simply need to call the FlattenForm method which returns a Boolean value, false if there are no fields found or true if the process succeeds.

See the code snippet below:

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


If you need to flatten specific fields you can call the FlattenFormField method passing in the name of the field. Again, the result is a Boolean value, false if the field is not found, otherwise true. You can obtain a list of interactive field names in a document by calling the GetFormFieldNames method which returns a string collection.

Let’s look at a code snippet:

    using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
         processor.LoadDocument("Demo.pdf");
         // Flatten all form fields with “Address” in their names.  
         processor.GetFormFieldNames()
              .Where(name => name.Contains("Address"))
              .ToList()
              .ForEach(name => processor.FlattenFormField(name));
 
         processor.SaveDocument("Result.pdf");
    }



Don’t forget, there is no way to undo the flattening process, so it would be a best practice to save the document as a different name!


As always, we would love to hear your feedback on this upcoming feature.


Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.