Show or Hide Photos in a PDF with Acrobat JavaScript
Question details
The user wants to attach photos to a PDF, identify them with JavaScript, and control their visibility in a form field.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Create a PDF that contains photos and lets users show or hide them through a form control.
- Observed behavior
- Attached files can be identified by name, but they are not ordinary page fields whose visibility can be changed.
Open the PDF in Adobe Acrobat and have the photos ready as supported image files or PDFs. Check that the intended PDF viewer supports Acrobat JavaScript and interactive form fields.
Place photos in button fields and control their visibility
Use button icons when photos need to appear on a PDF page and be shown or hidden with JavaScript.
A file attachment is separate from a page field. To control a photo's visibility, place it in a button field and change that field's display property.
In Acrobat, open All tools > Prepare a form, add a button where the photo should appear, and name it Photo1.
Open the button's Properties, select the Options tab, choose an icon-only layout, and use Choose Icon to select the photo or a PDF containing it.
Add another button in Prepare a form. In its Properties > Actions, select Mouse Up and Run a JavaScript, then add: this.getField("Photo1").display = display.hidden;
Add a separate button and set its Mouse Up action to Run a JavaScript with: this.getField("Photo1").display = display.visible;
Save the PDF, exit form editing, and click the show and hide buttons in a JavaScript-compatible PDF viewer. Repeat the setup with unique field names for additional photos.

Attach photos and list their names with Acrobat JavaScript
Use attachments when the photos should travel with the PDF as separate files rather than appear as controllable page fields.
Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its format compatibility makes it easy to bring existing files into your workflow. Use Acrobat for the JavaScript-based photo controls described above.

Frequently Asked Questions
Can JavaScript show or hide a PDF attachment like a form field?
No. Attachments are embedded files, not page fields. Place the photo in a button field and change that field's display property instead.
How can I find the names of files attached to a PDF?
In Acrobat's JavaScript console, inspect the document's dataObjects array. Each entry has a name property that identifies an embedded file.
How do I show a hidden photo button again?
Set its display property to visible. For a field named Photo1, use: this.getField("Photo1").display = display.visible;
Will the show and hide buttons work in every PDF viewer?
Not necessarily. Test the saved PDF in the intended viewer, because support for Acrobat JavaScript and interactive form fields varies.




