How to Create Buttons to Show or Hide Images in Adobe Acrobat
Question details
The user wants to create interactive buttons in a PDF document to toggle the visibility of specific images, such as corresponding elevation views in an architectural floor plan.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Enhancing an architectural floor plan PDF by adding buttons that open and close specific elevation images when clicked.
- Observed behavior
- Needs the correct method and JavaScript code to assign to a button's Mouse Up action to successfully toggle an image field's visibility state.
Ensure your elevation images are saved locally and confirm that your PDF editing software supports JavaScript for interactive form fields.
Create a Toggle Button Using JavaScript in Adobe Acrobat
Use an image field to insert your picture and apply a custom JavaScript code to a button's Mouse Up event to toggle the image's visibility.
By utilizing Adobe Acrobat's form preparation tools, you can easily create interactive elements. This method involves creating a dedicated image field to hold your graphic and linking its visibility state to a separate clickable button using a short JavaScript snippet.
Open your PDF in Adobe Acrobat and enter the 'Prepare Form' mode. Add an 'Image Field' to the document, insert your elevation image, and name the field appropriately (e.g., 'Picture_af_image').
From the form tools menu, select 'Button' and place it on your document where you want the interactive toggle switch to be located.
Right-click the newly created button and select 'Properties' from the context menu to configure its actions.
Navigate to the 'Actions' tab within the Properties window. Select 'Mouse Up' as the trigger, choose 'Run a JavaScript' from the 'Select Action' dropdown, and click 'Add'.
In the JavaScript editor, enter the following code: if (this.getField('Picture_af_image').display == display.visible) { this.getField('Picture_af_image').display = display.hidden; } else { this.getField('Picture_af_image').display = display.visible; } Click 'OK' and close the properties window to test your button.

Edit and Manage PDFs Seamlessly with WPS Office
While advanced JavaScript triggers are specialized features for complex form editors, WPS Office provides a comprehensive, lightweight, and user-friendly PDF editor. You can effortlessly insert, edit, and manage images, texts, and standard interactive elements in your PDFs without needing to write code.
- 1. Open the PDF: Launch WPS Office and open your architectural floor plan or PDF document.
- 2. Access the Edit Tools: Navigate to the 'Edit' tab located on the top ribbon to reveal the PDF modification options.
- 3. Insert or Edit Images: Use the 'Add Picture' tool to directly insert elevation images, or click on existing images to resize and reposition them.
- 4. Save the Document: Once your document is formatted correctly, click the 'Save' icon or export it to ensure your layout is preserved.

Frequently Asked Questions
Can I use this JavaScript toggle method to show or hide multiple images at once?
Yes. You can add multiple lines to the same button's Mouse Up event, targeting different field names. Simply repeat the toggle logic for each unique image field name you want the single button to control.
Why is my PDF button not hiding the image when clicked?
This usually happens if the field name referenced in your JavaScript does not exactly match the name of the image field in the document. Double-check for typos, spaces, and ensure the capitalization is identical.
Are JavaScript buttons in PDFs supported on mobile devices?
Interactive PDF elements that rely on JavaScript may not work correctly on all mobile PDF viewers or built-in browser readers. It is highly recommended to view these files on desktop applications like Adobe Acrobat or WPS Office for full compatibility.




