How to: Flatten Interactive Form Fields in a Document
- 3 minutes to read
Important
You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use these examples in production code. Refer to the DevExpress Subscription page for pricing information.
This example shows how to flatten interactive form fields (e.g., text fields, list boxes).
To flatten a whole interactive form, call the PdfDocumentProcessor.FlattenForm method. If the interactive form is flattened successfully, this method returns true. If the document doesn’t contain an interactive form that should be flattened, this method returns false.
To flatten a particular form field by its name, call the PdfDocumentProcessor.FlattenFormField method with a field name used as a parameter. This method tries to find the interactive form field in a document using the field name. If this form field is found in the document, then it will be flattened and this method returns true; otherwise, it returns false.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-flatten-an-interactive-form-t446039
Imports DevExpress.Pdf
Imports System
Namespace FlattenInteractiveForm
Friend Class Program
Shared Sub Main(ByVal args() As String)
Using processor As New PdfDocumentProcessor()
' Load a document with an interactive form.
processor.LoadDocument("..\..\Document.pdf")
' Flatten a form field by its name
If processor.FlattenFormField("Nationality") Then
' Save a document with the flattened form field.
processor.SaveDocument("..\..\Result1.pdf")
' Show a message if the form field was not found in a document.
Else
Console.WriteLine("A document does not contain a form field with the specified name to be flattened.")
End If
' Flatten a whole interactive form.
If processor.FlattenForm() Then
' Save a document with the flattened form.
processor.SaveDocument("..\..\Result2.pdf")
' Show a message if the interactive was not found in a document.
Else
Console.WriteLine("A document does not contain an interactive form to be flattened.")
End If
End Using
End Sub
End Class
End Namespace