How to Create Expandable or Collapsible Sections in a PDF Form
Question details
The user wants to create a PDF document with optional sections that can be shown or hidden by the reader, similar to the expandable and collapsible grouping controls found in Microsoft Excel.

- Product
- Adobe Acrobat / PDF Form
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF charter template that includes optional sections to keep the default view clean and user-friendly.
- Observed behavior
- Standard PDF authoring tools do not provide built-in Excel-style collapsible controls, requiring a workaround to achieve dynamic visibility for specific sections.
Ensure you are using a professional PDF editor with form-building and JavaScript support, as basic PDF viewers cannot create or execute the interactive elements required for this functionality.
Use Form Buttons and JavaScript to Toggle Visibility
Since PDFs lack native collapsible grouping, you can achieve this effect by assigning JavaScript actions to form buttons that toggle the display property of specific fields.
By grouping your optional content into specific form fields (like multiline text fields), you can control their display states using simple JavaScript functions triggered by a 'Show/Hide' button. This makes the PDF behave dynamically.
Add the text, checkbox, or data fields that you want to be collapsible. Name them using a consistent hierarchical naming convention, such as 'Section1.Field1'.
Use the 'Add Button' tool from your form editing menu to place a button near the section header. You can label it with a '+' sign or 'Expand/Collapse' in the button's appearance properties.
Right-click the newly created button, select 'Properties', and navigate to the 'Actions' tab.
Set the trigger to 'Mouse Up' and the action to 'Run a JavaScript'. Click 'Add' and enter the following script: `var field = this.getField("Section1"); field.display = (field.display == display.visible) ? display.hidden : display.visible;`
Save the script, close the properties dialog, and switch to the hand/preview tool to click the button and verify that the target fields appear and disappear correctly.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editing suite, allowing you to design interactive forms, insert text fields, checkboxes, and buttons easily without the steep learning curve of other heavy software.
- 1. Open WPS PDF: Launch WPS Office and open your existing PDF document or create a new one using the WPS PDF editor.
- 2. Access the Form tools: Navigate to the 'Form' tab on the top ribbon to reveal all interactive field options.
- 3. Insert form fields: Click on 'Text Field', 'Check Box', or 'Push Button' to start designing your document's interactive layout.
- 4. Modify field properties: Double-click or right-click any inserted field to adjust its appearance, name, and interactive actions.

Frequently Asked Questions
Can I create collapsible sections without using JavaScript in a PDF?
No, standard PDF formats do not support native collapsible groupings like Microsoft Word or Excel. Custom JavaScript tied to form buttons or checkboxes is strictly required to show or hide content dynamically.
Why aren't my hidden PDF form fields printing when they are expanded?
In the field properties under the 'General' tab, ensure the 'Form Field is' option is set to 'Visible'. If it is set to 'Visible but doesn't print', the content will appear on screen but will be omitted from physical or flattened prints.
Will these JavaScript expandable sections work on mobile PDF readers?
Often, they will not. Many mobile PDF viewers (such as built-in browser viewers or basic mobile apps) do not support PDF JavaScript. Users must open the form in a fully-featured PDF reader application for the interactive elements to function properly.




