How to Show or Hide PDF Template Pages Based on Multiple Checkboxes
Question details
The user needs a method to dynamically display or hide specific PDF template pages based on the selection of multiple checkboxes without having to create dozens of separate template combinations.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where multiple sections must be revealed or hidden depending on a user's checkbox selections.
- Observed behavior
- Managing a separate template for every possible checkbox combination (e.g., 31 combinations for 5 checkboxes) causes severe display conflicts and is difficult to maintain.
Ensure you are using a professional PDF editor that supports document-level JavaScript and interactive form fields. Always back up your original PDF file before adding or testing custom scripts.
Use a Document-Level JavaScript Function
By centralizing the logic into a single document-level JavaScript function, you can evaluate all checkboxes simultaneously and dynamically spawn or hide specific sections, avoiding the need for 31 separate templates.
Instead of maintaining a unique template for every possible combination of checkbox selections, you can use JavaScript to dynamically generate (spawn) or delete the individual template sections needed. This prevents overlap and keeps the document lightweight.
Open your PDF form in editing mode. Right-click each of the five checkboxes, select 'Properties', and navigate to the 'Options' tab. Assign a unique Export Value or identifier that logically corresponds to the template section it controls.
Go to your PDF editor's JavaScript settings and select 'Document JavaScripts'. Add a new script and give it a recognizable name (e.g., 'UpdateTemplates').
In the script editor, write a function that evaluates the state of all five checkboxes. Use the syntax `this.getField("CheckboxName").value` to check if a specific box is selected. Based on these values, determine which templates need to be shown.
Within the same function, utilize the PDF JavaScript API (such as `getTemplate("TemplateName").spawn()`) to generate the required pages, or clear previously spawned pages when the checkbox is deselected. Ensure your logic handles the sequence correctly to avoid display conflicts.
Return to the properties of your checkboxes. Under the 'Actions' tab, add an action for 'Mouse Up' that executes a JavaScript. Call your document-level function (e.g., `UpdateTemplates();`) so the pages update immediately when the user clicks.

Create and Manage Interactive PDF Forms Easily with WPS Office
WPS Office offers a comprehensive and user-friendly PDF editing suite. Whether you are adding interactive checkboxes, managing complex page layouts, or designing professional forms, WPS PDF streamlines the process without the need for expensive software.
- 1. Open Your PDF File: Launch WPS Office and open your PDF document using the built-in WPS PDF tool.
- 2. Access Form Controls: Navigate to the 'Form' tab on the top ribbon to easily insert checkboxes and interactive elements into your document.
- 3. Manage Document Pages: Use the 'Page' tab to quickly extract, insert, or reorganize your document layout to ensure all sections are displayed correctly.

Frequently Asked Questions
Why do my PDF template pages overlap when multiple checkboxes are checked?
Overlap usually occurs when multiple independent scripts try to spawn pages into the same index or without checking existing pages. Using a single document-level script to coordinate the visibility of all templates prevents these display conflicts.
Do I need coding experience to hide or show PDF template pages?
Yes, dynamically hiding and showing specific PDF templates based on complex conditions requires basic knowledge of JavaScript and familiarity with the PDF JavaScript API.
Can standard PDF pages be hidden instead of using templates?
Standard PDF pages cannot be hidden or unhidden easily in a standard PDF viewer. Instead, developers use 'Templates'—which are hidden by default—and use scripts to dynamically 'spawn' (create) them as visible pages when required.




