Hide and Show an Image With a Button in Adobe Acrobat
Question details
The user wants an Acrobat form button to hide a PNG image on one click and show it again on the next.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form contains an image and a button that should toggle the image's visibility.
- Observed behavior
- The desired result is for the same button to alternate the image between hidden and visible.
Open the PDF in a version of Adobe Acrobat that can edit forms, and have the PNG file available. The image must be placed in an image field for the button script to control it.
Toggle an Acrobat Image Field With a Button Script
Use a Mouse Up JavaScript action to switch an image field between visible and hidden each time the button is clicked.
Open All tools > Prepare a form, select the image field tool, and draw a field where the PNG should appear. If the original PNG is a separate page image, remove it or replace it with the image field so it does not remain visible.
Close Prepare a form, click the new image field, and select the PNG file. Reopen Prepare a form and check the field name in the Fields list or field properties.
In Prepare a form, open the button's Properties and select the Actions tab. Set Select Trigger to Mouse Up, choose Run a JavaScript, and click Add.
In the JavaScript editor, enter: var f = this.getField("Image1_af_image"); f.display = f.display == display.visible ? display.hidden : display.visible; Replace Image1_af_image with the actual name of the image field, then save the action.
Close Prepare a form and click the button twice: the image should disappear on the first click and return on the second. Save the PDF after testing.

Work With PDFs and Office Files in WPS Office
WPS Office is a free, lightweight alternative for everyday PDF and Office work, with a familiar interface and support for common Microsoft Office formats to help you migrate existing files. Use Adobe Acrobat to create and test the JavaScript image toggle described above.

Frequently Asked Questions
How do I find the image field name for the script?
Open All tools > Prepare a form and inspect the Fields list or the image field's properties. Use the exact field name inside this.getField(), including any suffix.
Can the script hide a PNG placed directly on the PDF page?
The script controls a form field, not a separate page image. Add the PNG to an image field in Prepare a form and use that field's name in the script.
Why does the button not work in another PDF viewer?
The viewer may not support Acrobat JavaScript or may have JavaScript disabled. Test the saved form in Acrobat and check Preferences > JavaScript for the JavaScript setting.
Will the text move into the space when the image is hidden?
No. Changing the image field's display property hides the field but leaves its page area blank; the surrounding PDF content does not reflow.




