How to Move PDF Form Fields with JavaScript Using the Rect Property
Question details
The user needs to change the position of a PDF form field or button dynamically using JavaScript when triggered by another button.

- 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.
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.
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.
Open your PDF document in a compatible PDF editor and navigate to the interactive form editing tools.
Right-click the button that will act as the trigger and select 'Properties' from the context menu.
Go to the 'Actions' tab, select 'Run a JavaScript' from the action dropdown menu, and click 'Add'.
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.
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.

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. Open your PDF: Launch WPS Office and open your interactive PDF document.
- 2. Access form tools: Navigate to the 'Form' tab on the top ribbon to access all interactive elements.
- 3. Edit buttons and fields: Click on 'Edit Form' to modify field properties, assign names, and configure button behaviors.
- 4. Save your interactive document: Once your JavaScript actions are set up, export or save the file to retain all interactive functions.

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.




