PDF Editing Issues

How to Resize Acrobat Form Fields with JavaScript Conditions

Amos GikundaAmos Gikunda Nov 10, 2026 871 views

Question details

The user needs to use JavaScript to dynamically adjust the dimensions of a PDF form field and hide an adjacent price field when a specific text condition is met.

How to Resize Acrobat Form Fields with JavaScript Conditions
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating interactive PDF forms where the layout needs to adapt automatically based on the text input provided by the user.
Observed behavior
The goal state is to have the deficiency field expand and the price field disappear when the word 'Note' is entered, and to restore the original layout when the condition is false.
Before you start

Ensure you have access to Adobe Acrobat Pro or a PDF editor that supports document-level JavaScript and advanced form field property modifications.

Solution 1Recommended

Use the rect Property and Regular Expressions

Implement conditional JavaScript using the Acrobat `rect` property to change dimensions and the `hidden` property to toggle visibility.

In Adobe Acrobat, field sizes and positions are defined by the `rect` property, which requires an array of four coordinates: [left, top, right, bottom]. Common variables like 'x' or 'w' are not valid in Acrobat's JavaScript API. For efficient scripting, define your variables and field numbers outside of the conditional blocks, and use a case-insensitive regular expression to detect trigger words.

1
Open Prepare Form mode

Open your PDF document in Adobe Acrobat, navigate to 'Tools', and select 'Prepare Form' to enable form editing.

2
Access field properties

Right-click the target text field (e.g., the deficiency field) that will trigger the script and select 'Properties'.

3
Add a custom script

Go to the 'Format' or 'Calculate' tab, select 'Custom calculation script' or custom format script, and click 'Edit'.

4
Define variables

Write the initial variable declarations to retrieve the field number and price field: var defNumber = event.target.name.slice(-1); var priceFld = this.getField("exteriorElectricalPrice" + defNumber);

5
Apply conditional logic with the rect property

Add the conditional block using a regular expression: if (/note/i.test(event.value)) { priceFld.hidden = true; event.target.rect = [event.target.rect[0], event.target.rect[1], event.target.rect[0] + 7.2112 * 72, event.target.rect[3]]; } else { priceFld.hidden = false; }

6
Test the form

Close the properties dialog, exit form editing mode, and type 'Note' into the field to verify the script triggers the resizing and hiding properly.

Use the rect Property and Regular Expressions
Acrobat Coordinate System: Acrobat PDF page coordinates are measured in points (72 points per inch), originating from the bottom-left corner of the page.
Powerful PDF Editing & Form Tools

Edit PDFs and Manage Forms Easily with WPS Office

While complex dynamic JavaScript behaviors require advanced coding in Acrobat, WPS Office provides an intuitive, lightweight PDF editor that lets you easily create, fill, and modify standard PDF forms without writing code.

  1. 1. Launch WPS Office: Open WPS Office and click on 'PDF Edit' from the home dashboard to load your document.
  2. 2. Access Form Controls: Navigate to the 'Form' tab on the top ribbon to view all available form tools and interactive elements.
  3. 3. Modify Field Properties: Double-click any existing form field to open the properties panel, where you can easily adjust its appearance, size, and visibility.
Easily add, edit, and fill interactive PDF form fields with a user-friendly interfaceHighly compatible with standard PDF formats and Microsoft Office document typesSeamlessly convert PDFs to Word, Excel, and PowerPoint for easier layout editingCross-platform support for Windows, Mac, Linux, iOS, and Android devices
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't changing the 'w' or 'x' property resize my Acrobat form field?

Adobe Acrobat's JavaScript API does not recognize 'w' (width) or 'x' for field dimensions. To resize a field, you must manipulate its `rect` property, which takes an array of four coordinate values representing the field's boundaries: [left, top, right, bottom].

How do I make a PDF form field hidden using JavaScript?

You can easily toggle the visibility of a field by altering its `hidden` property. For example, using `this.getField("FieldName").hidden = true;` will hide the field from view.

How do I check if a field contains a specific word regardless of capitalization?

Use a regular expression with the `test()` method and the `i` flag for case insensitivity. For example, `/note/i.test(event.value)` evaluates to true whether the user types 'note', 'Note', or 'NOTE'.

Why is my Acrobat script returning a null value for my target field?

This commonly happens if the field name string is incorrect or if variables are defined inside a conditional statement where they are not properly initialized. Always retrieve your field objects (e.g., using `this.getField()`) before executing your conditional statements.