Remove form fields

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Viewer MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-viewer -- dnx GroupDocs.Viewer.Mcp --yes
Folders, licensing and more →

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("order_form.pdf") 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()

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

Binary file (PDF, 207 KB)

Download full output

On this page