Remove form fields

On this page

If the output PDF file contains form fields, you can flatten them to reduce the file size.

To remove form fields, set the remove_form_fields property to True.

The following code snippet shows how to flatten form fields in the file:

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions, PdfOptimizationOptions

def remove_form_fields():
    # Load document
    with Viewer("sample.docx") as viewer:
        viewOptions = PdfViewOptions("remove_form_fields/without_form_fields.pdf")
        viewOptions.pdf_optimization_options = PdfOptimizationOptions()
        viewOptions.pdf_optimization_options.remove_form_fields = True

        viewer.view(viewOptions)

if __name__ == "__main__":
    remove_form_fields()

sample.docx is the sample file used in this example. Click here to download it.

The following image demonstrates the result:

Remove fields

On this page

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.