PDF Editing Issues

How to Copy an Image Field Between PDF Forms Using JavaScript

Bushra ParveenBushra Parveen Nov 3, 2026 870 views

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.

How to Copy an Image Field Between PDF Forms Using JavaScript
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.
Before you start

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.

Solution 1Recommended

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.

1
Identify the Source and Destination Fields

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.

2
Retrieve the Source Icon

Use the JavaScript method buttonGetIcon() on your source field object to extract the image. For example: var myIcon = this.getField('sourceFieldName').buttonGetIcon();

3
Assign to Destination Field

Apply the retrieved icon to your destination field using the buttonSetIcon() method. For example: this.getField('destinationFieldName').buttonSetIcon(myIcon);

Use buttonGetIcon and buttonSetIcon Methods
Syntax Reference: Always ensure the field names in your script perfectly match the names defined in the PDF form properties. Refer to the standard PDF JavaScript API Reference for further details on field methods.
Edit PDF Forms Easily

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. 1. Open your PDF: Launch WPS Office and open your target PDF form document.
  2. 2. Enter Edit Mode: Navigate to the 'Edit' tab on the top ribbon to enable modifications to text and images.
  3. 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.
Easily insert, replace, and duplicate images within PDFsHighly compatible with standard PDF forms and document layoutsLightweight application with a comprehensive suite of PDF editing toolsFamiliar user interface for seamless document management
microsoft office alternative - wps office

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.