ceTe Software Help Library for Java August - 2020
DynamicPDF Merger for Java / Programming with Merger for Java / Working With AcroForms / Form Flattening
In This Topic
    Form Flattening
    In This Topic

    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.

    Document Level Flattening

    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");
    

    Field Level Flattening

    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");
    

    Preserving Digital Signatures During Flattening

    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);
    
    See Also