How to Copy an Image Field Between PDF Forms Using JavaScript
Question details
The user needs to programmatically copy an image from one PDF form field to another using JavaScript but finds that assigning values directly does not work.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Duplicating or transferring an image from one field to another programmatically within an interactive PDF form.
- Observed behavior
- Assigning the field value directly fails because PDF image fields function as button fields, storing the displayed image as an icon rather than a standard field value.
Ensure you have access to a PDF editor with form editing capabilities and a built-in JavaScript console or editor to execute document-level or field-level scripts.
Use buttonGetIcon and buttonSetIcon Methods
Retrieve the image as a button icon from the source field and apply it to the destination field using specific JavaScript methods.
In PDF forms, image fields are typically structured as button fields. This means the image itself is stored as the button's icon, not as a standard text or data value. Therefore, standard value assignment (e.g., field1.value = field2.value) will fail to transfer the image.
Locate the exact field names of the source image field (where the image currently resides) and the destination image field within your PDF form properties.
Use the JavaScript method buttonGetIcon() on your source field object to extract the image. For example: var myIcon = this.getField('sourceFieldName').buttonGetIcon();
Apply the retrieved icon to your destination field using the buttonSetIcon() method. For example: this.getField('destinationFieldName').buttonSetIcon(myIcon);

Manage PDF Forms and Images with WPS Office
While scripting provides programmatic control, WPS Office offers a highly intuitive PDF interface to visually add, edit, and duplicate images and form elements across your documents without needing to write any code.
- 1. Open your PDF: Launch WPS Office and open your target PDF form document.
- 2. Enter Edit Mode: Navigate to the 'Edit' tab on the top ribbon to enable modifications to text and images.
- 3. Copy and Paste: Select the image or object you wish to duplicate, right-click to copy it, and paste it into the desired location.

Frequently Asked Questions
Why doesn't assigning a field value duplicate my PDF image?
In standard PDF architecture, image fields are constructed as interactive button fields. The image is rendered as the button's icon rather than stored in the field's underlying data value, requiring icon-specific methods to manipulate.
Can I copy PDF form fields without using JavaScript?
Yes, most advanced PDF editors allow you to manually copy and paste form fields in Form Editing mode, which will duplicate the field's appearance, size, and settings without any scripting.
What is the correct object type returned by buttonGetIcon?
The buttonGetIcon() method returns an Icon object. This object represents the appearance stream of the button and can only be assigned to another button field using the buttonSetIcon() method.




