PDF Editing Issues

Show or Hide Photos in a PDF with Acrobat JavaScript

Olivia MillerOlivia Miller Nov 19, 2026 870 views

Question details

The user wants to attach photos to a PDF, identify them with JavaScript, and control their visibility in a form field.

Show or Hide PDF Photos with Acrobat JavaScript
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.
Before you start

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.

Solution 1Recommended

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.

1
Create a photo field

In Acrobat, open All tools > Prepare a form, add a button where the photo should appear, and name it Photo1.

2
Add the photo as an icon

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.

3
Add a hide control

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;

4
Add a show control

Add a separate button and set its Mouse Up action to Run a JavaScript with: this.getField("Photo1").display = display.visible;

5
Test the controls

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.

Place photos in button fields and control their visibility
Visibility is not security: Hiding a field does not remove the photo or protect it from someone who can edit or inspect the PDF.
Free Microsoft Office alternative

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.

Open and work with PDF documents in one office suiteCompatible with Microsoft Word, Excel, and PowerPoint formatsFamiliar interface for a smoother move from Microsoft OfficeFree and lightweight for everyday document work
microsoft office alternative - wps office

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.