PDF Editing Issues

How to Move PDF Form Fields with JavaScript Using the Rect Property

John WilsonJohn Wilson Nov 5, 2026 869 views

Question details

The user needs to change the position of a PDF form field or button dynamically using JavaScript when triggered by another button.

How to Move PDF Form Fields with JavaScript Using the Rect Property
Product
PDF Editor
Device & OS
not provided
Scenario
Creating an interactive PDF form where user actions trigger dynamic layout changes, such as repositioning form fields on the page.
Observed behavior
The user intends to execute an Acrobat JavaScript command targeting the field's rect property to redefine its page coordinates.
Before you start

Ensure your PDF editor supports form JavaScript execution and that you know the exact page coordinates (left, top, right, bottom) for the new field position.

Solution 1Recommended

Modify Field Coordinates Using a Button Action

Apply a JavaScript action to a trigger button that targets a specific form field and sets its new location using the rect property.

The rect property in PDF JavaScript is represented by an array of four coordinate numbers: [left, top, right, bottom]. These values dictate the exact bounding box of the field in points. The origin (0,0) is typically located at the bottom-left corner of the document page.

1
Enter form editing mode

Open your PDF document in a compatible PDF editor and navigate to the interactive form editing tools.

2
Access button properties

Right-click the button that will act as the trigger and select 'Properties' from the context menu.

3
Add a JavaScript action

Go to the 'Actions' tab, select 'Run a JavaScript' from the action dropdown menu, and click 'Add'.

4
Enter the rect property script

In the script editor, enter the code: this.getField("Text1").rect = [400, 427, 412, 415]; Replace 'Text1' with the exact name of the field you want to move, and adjust the four coordinates to match your desired placement.

5
Save and test

Click 'OK' to save the script, close the properties window, exit form editing mode, and click your button to verify the target field moves correctly.

Modify Field Coordinates Using a Button Action
Coordinate Mapping: Finding the exact coordinates can involve trial and error. It is helpful to temporarily draw a test field where you want the new location to be, check its default rect properties, and use those values in your script.
Create Interactive PDFs with WPS Office

Easily Build and Edit PDF Forms with WPS PDF

WPS Office includes a comprehensive PDF editor that allows you to insert form fields, manage interactive buttons, and process document JavaScript to make your PDFs dynamic.

  1. 1. Open your PDF: Launch WPS Office and open your interactive PDF document.
  2. 2. Access form tools: Navigate to the 'Form' tab on the top ribbon to access all interactive elements.
  3. 3. Edit buttons and fields: Click on 'Edit Form' to modify field properties, assign names, and configure button behaviors.
  4. 4. Save your interactive document: Once your JavaScript actions are set up, export or save the file to retain all interactive functions.
Fully compatible with Adobe Acrobat form fields and PDF JavaScript.Easily insert text fields, checkboxes, buttons, and drop-down menus.Lightweight, fast-loading, and user-friendly PDF editing interface.Cross-platform support for seamless document management.
microsoft office alternative - wps office

Frequently Asked Questions

What do the four numbers in the rect property represent?

The array contains four numbers [left, top, right, bottom] that define the exact coordinates of the field's bounding box. These are measured in points (1/72 of an inch) from the bottom-left corner of the page.

Can I use the rect property to move a field to a different page?

No, the rect property only changes the position of the field on the page it currently resides on. To move a field to a different page, you must adjust the 'page' property or recreate the field programmatically.

Will this JavaScript work on all PDF viewers?

While this standard JavaScript works perfectly on robust desktop editors like WPS PDF and Adobe Acrobat, many basic web browsers or mobile PDF readers have limited JavaScript engines and may not execute the repositioning script.