PDF Editing Issues

How to Flatten PDF Form Fields and Hide the Button

John WilsonJohn Wilson Nov 2, 2026 869 views

Question details

The user wants to execute a script via a visible PDF button to flatten form fields, but needs the button itself to be hidden in the final flattened document.

How to Flatten PDF Form Fields and Hide the Button
Product
PDF Editor
Device & OS
not provided
Scenario
Creating a dynamic PDF form where users can click a button to finalize and flatten the document without leaving the button visible on the completed page.
Observed behavior
If the form is flattened first, the button becomes permanently visible as part of the document content, so the user needs to know the exact execution order to hide it.
Before you start

Verify that your PDF software supports JavaScript execution and document flattening, as standard free readers cannot alter the base structure of a PDF.

Solution 1Recommended

Hide the Button Before Executing the Flatten Command

Adjust your JavaScript sequence so the button is hidden prior to the flattening action, ensuring it does not become a permanent visual element on the page.

When a PDF is flattened, interactive elements like buttons are merged into the underlying page content. If the flattening happens first, the button is permanently stamped onto the document, and any subsequent command to hide it will fail. By changing the button's display property to hidden first, the script will still finish running the flatten command seamlessly in the background.

1
Access Button Properties

Enter form editing mode in your advanced PDF editor, right-click the specific button you want to use, and select 'Properties'.

2
Edit the Action Script

Navigate to the 'Actions' tab, select 'Run a JavaScript' from the drop-down menu, and click 'Edit' or 'Add' to open the JavaScript editor window.

3
Add the Hide Command

At the very top of your script, insert the command to hide the button. For example: event.target.display = display.hidden;

4
Add the Flatten Command

Directly below the hide command, insert your document flattening command (e.g., this.flattenPages();). Save your changes and test the button.

Hide the Button Before Executing the Flatten Command
Software Limitation: This specific JavaScript action requires an advanced PDF editor like Acrobat Pro or Acrobat Standard. Standard reader applications will not execute page flattening.
Edit and Flatten PDFs Easily

Manage and Flatten PDF Forms Intuitively with WPS Office

If you need an easier way to manage PDF documents without writing custom JavaScript, WPS Office provides a robust suite of PDF tools that let you fill, edit, and flatten forms effortlessly.

  1. 1. Open the PDF Form: Launch WPS Office and open the interactive PDF form you wish to finalize.
  2. 2. Access PDF Editing Tools: Navigate to the top ribbon and select the 'Protect' or 'Form' tab depending on your interface layout.
  3. 3. Flatten and Save: Use the built-in option to export or print the document to PDF, which automatically flattens all form fields and annotations into the base document, removing the need for complex buttons and scripts.
Intuitive graphical interface for filling and flattening PDF formsHighly compatible with standard Adobe Acrobat PDF formatsLightweight software that runs smoothly on low-spec devicesIncludes advanced document protection and annotation features
microsoft office alternative - wps office

Frequently Asked Questions

Why does my button remain visible after clicking it?

This happens when your script executes the flatten command before the hide command. Flattening converts all active fields, including buttons, into standard page images. You must code the script to hide the button first.

Can I flatten a PDF form using a free standard reader?

Generally, no. Form flattening alters the core structure of the document, an action restricted to advanced editors like Acrobat Pro, Acrobat Standard, or premium PDF tools. Free readers usually only allow you to view or fill out the form.

Will hiding the button stop the rest of my script from running?

No, changing a button's visibility property to hidden does not terminate the script. The JavaScript engine will continue executing the subsequent lines of code, including the flattening command, sequentially.