Create Incrementing PDF Text Fields with Acrobat JavaScript
Question details
Create PDF text fields with sequential names and values using Acrobat JavaScript.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form needs many numbered text fields without assigning each number manually.
- Observed behavior
- Each new field should receive an unused name and the next sequential value based on existing generated fields.
Open the PDF in Adobe Acrobat with permission to edit form fields, and enable Acrobat JavaScript in Preferences if it is disabled. This example uses the prefix SeqText_ and places fields on the first page, so check that the prefix and placement will not conflict with existing form content.
Scan existing field names and create the next numbered field
Use this method when the script may be run repeatedly and must continue after the highest existing generated field number.
The script scans names matching SeqText_ followed by a number, then uses the highest number plus one for both the new field name and its value. It does not fill gaps in the sequence.
Each run creates one field in a vertical row on the first page. Adjust the coordinates for your form, and make sure the row does not overlap existing content.
In Acrobat, open the PDF and launch the JavaScript console. On Windows, press Ctrl+J; if the console is unavailable, check the JavaScript settings in Preferences.
Paste and execute this script in the console: var doc = this; var maxNumber = 0; for (var i = 0; i < doc.numFields; i++) { var match = /^SeqText_(\d+)$/.exec(doc.getNthFieldName(i)); if (match) maxNumber = Math.max(maxNumber, parseInt(match[1], 10)); } var next = maxNumber + 1; var box = doc.getPageBox("Crop", 0); var left = box[0] + 36; var top = box[1] - 36 - (next - 1) * 24; if (left + 80 > box[2] - 36 || top - 18 < box[3] + 36) { app.alert("No room in the configured field area. Adjust the page or coordinates."); } else { var field = doc.addField("SeqText_" + next, "text", 0, [left, top, left + 80, top - 18]); field.value = String(next); }
Execute the script again for each additional field. Open Prepare a form to inspect or adjust the fields, then use File > Save to save the PDF.

Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and support for common Microsoft Office formats, making it easy to move between everyday documents. Use Adobe Acrobat for the Acrobat-specific JavaScript field-creation script.

Frequently Asked Questions
Will the script reuse a missing field number?
No. It finds the highest existing SeqText_ number and adds one. For example, if SeqText_1 and SeqText_3 exist, the next field will be SeqText_4.
Can I create hundreds of fields with this example?
The example creates one field per run and stops when the configured row runs out of space on page one. To create hundreds, adapt the script to loop and place fields across multiple pages.
Why does the script report that there is no room?
The calculated field position is outside the configured first-page area. Adjust the page index or the left, top, spacing, and field-size values in the script.
Can I use Acrobat Reader to create these form fields?
The script requires a version of Acrobat that can edit PDF form fields and a PDF that permits editing. Acrobat Reader alone is not intended for creating form fields.




