Flattening the form fields of a PDF is the process that will take the values of the form fields, add them to the actual PDF stream and then remove all of 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 in which the field values not as easily edited.
The following example demonstrates how to flatten all the form fields within a PDF:
[Java]
MergeDocument document = new MergeDocument("[PhysicalPath]/AcroForm.pdf");
document.getForm().setOutput(FormOutput.FLATTEN);
document.draw("[PhysicalPath]/AcroForm_Flattened.pdf");
The following example demonstrates how to flatten individual form field within a PDF:
[Java]
MergeDocument document = new MergeDocument("[PhysicalPath]/AcroForm.pdf");
document.getForm().getFields().getFormField(0).setOutput(FormFieldOutput.FLATTEN);
document.draw("[PhysicalPath]/AcroForm_Flattened.pdf");
By default, Digital Signatures will be 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 DigitalSignatures property of the FormFlatteningOptions. Adding the following line to the above example would retain all the Digital Signatures:
[Java]
document.getForm().setSignatureFieldsOutput(FormFieldOutput.RETAIN);