PDF Editing Issues

How to Create Expandable or Collapsible Sections in a PDF Form

Phi Hung VoPhi Hung Vo Nov 3, 2026 868 views

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.

How to Create Expandable and Collapsible Sections in a PDF Form
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.
Before you start

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.

Solution 1Recommended

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.

1
Create the target form fields

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'.

2
Add a toggle button

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.

3
Access button properties

Right-click the newly created button, select 'Properties', and navigate to the 'Actions' tab.

4
Add the JavaScript action

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;`

5
Test the interactive form

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.

Use Form Buttons and JavaScript to Toggle Visibility
Hierarchical Naming: If you name your fields hierarchically (e.g., 'Section1.Row1', 'Section1.Row2'), you can toggle the visibility of the entire 'Section1' group with a single line of JavaScript by referencing 'Section1'.
Edit PDF Forms Easily

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. 1. Open WPS PDF: Launch WPS Office and open your existing PDF document or create a new one using the WPS PDF editor.
  2. 2. Access the Form tools: Navigate to the 'Form' tab on the top ribbon to reveal all interactive field options.
  3. 3. Insert form fields: Click on 'Text Field', 'Check Box', or 'Push Button' to start designing your document's interactive layout.
  4. 4. Modify field properties: Double-click or right-click any inserted field to adjust its appearance, name, and interactive actions.
Easily insert text fields, checkboxes, and interactive push buttons.Fully compatible with standard Adobe PDF form formats.Lightweight, fast, and feature-rich alternative for reading and editing PDF files.Cross-platform support for Windows, Mac, and mobile devices.
microsoft office alternative - wps office

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.