How to Import or Clear an Image Using One PDF Button
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.

- 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.
Ensure you have access to the PDF JavaScript console and that your PDF editor supports advanced form field scripting.
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.
Right-click your interactive form button and open its Properties dialog. Navigate to the Actions tab to add a custom JavaScript trigger.
Write a conditional statement to check if an image is loaded. If no image is present, execute 'event.target.buttonImportIcon();'.
In the alternative condition (when an image already exists), set 'event.target.buttonPosition = position.textOnly;' to hide the current image.
Switch back to the standard document selection tool, click the button to import an image, and click it again to ensure it clears successfully.

Update to a Supported PDF Software Version
Older versions of PDF software may have bugs with JavaScript functions and lack full API support.
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. Open your PDF in WPS Office: Launch WPS Office and open your target PDF document.
- 2. Enter Edit Mode: Click on the 'Edit' tab at the top toolbar and select 'Edit Image'.
- 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.

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.




