PDF Editing Issues

How to Import or Clear an Image Using One PDF Button

Jason MillerJason Miller Nov 5, 2026 869 views

Question details

The user wants to configure a single interactive PDF form button to either import a new image or clear the existing image based on its current state.

How to Import or Clear an Image with a Single PDF Form Button
Product
Adobe Acrobat / PDF
Device & OS
not provided
Scenario
Creating an interactive PDF form where users can upload a photo or signature, and subsequently remove it using the exact same button.
Observed behavior
The PDF software does not provide a direct JavaScript command to clear an image icon, making it difficult to reset the button state using standard stream comparisons.
Before you start

Ensure you have access to the PDF JavaScript console and that your PDF editor supports advanced form field scripting.

Solution 1Recommended

Use Button Position State to Clear the Image

Instead of comparing complex icon streams, change the button's layout position state to text-only to effectively hide and clear the displayed image.

Comparing icon streams (such as using util.iconStreamFromIcon) can be unreliable and often throws errors if an icon is invalid or missing.

A much simpler and more stable approach is to manipulate the button's layout position. By setting the button's position to 'textOnly', the PDF viewer automatically hides the image icon, achieving the cleared effect without needing a blank replacement image file.

1
Open button properties

Right-click your interactive form button and open its Properties dialog. Navigate to the Actions tab to add a custom JavaScript trigger.

2
Add the import logic

Write a conditional statement to check if an image is loaded. If no image is present, execute 'event.target.buttonImportIcon();'.

3
Add the clear logic

In the alternative condition (when an image already exists), set 'event.target.buttonPosition = position.textOnly;' to hide the current image.

4
Test the button script

Switch back to the standard document selection tool, click the button to import an image, and click it again to ensure it clears successfully.

Use Button Position State to Clear the Image
Handling Invalid Icons: Remember that the buttonGetIcon function can return an invalid icon when no image is loaded. Always test your scripts with the JavaScript Console open to catch and debug any hidden errors.

Easily Edit and Manage PDF Images with WPS Office

If scripting PDF form buttons is too complex, you can easily insert, replace, or delete images directly using the intuitive editing tools in WPS PDF.

  1. 1. Open your PDF in WPS Office: Launch WPS Office and open your target PDF document.
  2. 2. Enter Edit Mode: Click on the 'Edit' tab at the top toolbar and select 'Edit Image'.
  3. 3. Add or Remove Images: Click on any existing image to delete or replace it, or use the 'Add Image' button to insert a new graphic instantly.
Directly insert, replace, or delete images in PDFs without writing any JavaScript.Create, manage, and fill interactive PDF forms effortlessly.Fully compatible with standard PDF formats and Adobe Acrobat files.Lightweight, fast, and highly intuitive user interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't comparing icon streams work in my PDF form?

Comparing icon streams using 'util.iconStreamFromIcon' can be unreliable because functions like 'buttonGetIcon' might return an invalid or empty object when no image is loaded, causing the comparison script to fail.

Can I reset a PDF form button to a blank image?

Yes. You can either import a transparent PDF page to serve as a blank icon, or simply change the button's layout property to 'position.textOnly' using JavaScript, which effectively hides the current image.

Does WPS PDF support interactive form fields?

Yes, WPS PDF supports viewing, filling, and interacting with standard PDF form fields, making it simple to process user-submitted data and manage electronic documents.