How to Flatten PDF Form Fields and Hide the Button
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.

- 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.
Verify that your PDF software supports JavaScript execution and document flattening, as standard free readers cannot alter the base structure of a PDF.
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.
Enter form editing mode in your advanced PDF editor, right-click the specific button you want to use, and select 'Properties'.
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.
At the very top of your script, insert the command to hide the button. For example: event.target.display = display.hidden;
Directly below the hide command, insert your document flattening command (e.g., this.flattenPages();). Save your changes and test the button.

Use a Bookmark to Trigger Form Flattening
Instead of placing a visible button directly on the document canvas, use a PDF bookmark to run the flattening script.
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. Open the PDF Form: Launch WPS Office and open the interactive PDF form you wish to finalize.
- 2. Access PDF Editing Tools: Navigate to the top ribbon and select the 'Protect' or 'Form' tab depending on your interface layout.
- 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.

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.




