Flattening the form fields of a PDF is the process that takes the values of the form fields, adds them to the PDF stream, and then removes the form field structures from the document. The advantages of flattening form fields are that you achieve a PDF that is simpler and smaller, as well as a PDF where the field values can be more easily edited.
Document Level Flattening
The FormOutput.Flatten option flattens a PDF's form fields. A MergeDocument has a Form property that represents a document's form. The Form class has an Output property that is a FormOutput enumeration.
|FormOutput.Flatten||0||Form fields will be flattened.|
|FormOutput.Remove||1||Form fields will be removed.|
|FormOutput.Retain||2||Form fields will be retained.|
The following example demonstrates how to flatten a PDF's form fields using the FormOutput.Flatten enumeration choice.
MergeDocument document = new MergeDocument(pdfFilePath); document.Form.Output = FormOutput.Flatten; document.Draw(pdfFilePath);
Dim document As MergeDocument = New MergeDocument(pdfFilePath) document.Form.Output = FormOutput.Flatten document.Draw(pdfFilePath)
Field Level Flattening
Individual fields can also be flattened rather than an entire form. A MergeDocument has a Form property, which has a Fields property. The Fields property is a FormFieldsList that contains the individual form fields. The FormField class has an Output property that accepts a FormFieldOutput enumeration.
|FormFieldOutput.Flatten||0||The field will be flattened.|
|FormFieldOutput.Inherit||3||Field's output will depend on the document's form level output settings.|
|FormFieldOutput.Remove||1||The field will be removed.|
|FormFieldOutput.Retain||2||The field will be retained.|
The following example demonstrates how to flatten individual form field within a PDF.
MergeDocument document = new MergeDocument(pdfFilePath); document.Form.Fields.Output = FormFieldOutput.Flatten; document.Draw(pdfFilePath);
Dim document As MergeDocument = New MergeDocument(pdfFilePath) document.Form.Fields(0).Output = FormFieldOutput.Flatten document.Draw(pdfFilePath);
Preserving Digital Signatures During Flattening
Digital Signatures are default flattened along with all the other form fields in the PDF (as shown above). If you wish to retain the Digital Signatures during the form field flattening, then you can use the Form class's SignatureFieldsOutput property, which takes a FormFieldOutput enumeration. Adding the following line to the above example would retain the Digital Signatures.
document.Form.SignatureFieldsOutput = FormFieldOutput.Retain;
document.Form.SignatureFieldsOutput = FormFieldOutput.Retain