Combine PDF Form Fields Into a Numbered List With Acrobat JavaScript
Question details
Combine multiple PDF text field values into one numbered, multiline summary field.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form contains several text fields whose nonempty values should appear in a single summary field.
- Observed behavior
- The desired summary displays each nonempty value on a separate line, numbered consecutively.
Identify the exact names of the source fields and the summary field in Acrobat's Prepare a form tool. Make sure the summary field is a text field and is not included among the source fields.
Use a Custom Calculation Script in the Summary Field
Use this approach to automatically collect nonempty field values and number them without gaps.
In Adobe Acrobat, open the PDF and select All tools > Prepare a form. Double-click the summary text field to open its Properties dialog.
In the Properties dialog, open the Options tab and select Multi-line so the summary can display each entry on a separate line.
Open the Calculate tab, select Custom calculation script, and click Edit. Paste this script, replacing Field1, Field2, and Field3 with the exact source field names: var fields = ["Field1", "Field2", "Field3"]; var values = []; for (var i = 0; i < fields.length; i++) { var field = this.getField(fields[i]); if (field) { var v = field.valueAsString; if (v.replace(/^\s+|\s+$/g, "")) { values.push((values.length + 1) + ". " + v); } } } event.value = values.join("\n");
Close the script editor and Properties dialog, then save the PDF. Enter values in several source fields, leaving at least one blank, and check that the summary has consecutive numbers on separate lines.

Work With PDFs and Office Documents in WPS Office
WPS Office is a free, lightweight, easy-to-use alternative for working with PDFs and Office documents. Its familiar interface and format compatibility make it easy to move existing files into your workflow. Use Acrobat to create and test the JavaScript calculation described above.

Frequently Asked Questions
Why are the entries joined on one line?
In the summary field's Properties > Options tab, enable Multi-line. In the custom calculation script, use values.join("\n") to put a newline between entries.
How does the script skip empty fields without leaving gaps in the numbering?
The script adds a value only when it contains non-whitespace text. It uses values.length + 1 for the next number, so skipped fields do not create gaps.
Where do I find the field names for the script?
Open All tools > Prepare a form in Acrobat and inspect the form fields. Use each source field's exact name in the script's fields array, and leave out the summary field.
Why doesn't the summary update in my PDF viewer?
The viewer must support Acrobat form JavaScript. Test the form in Acrobat and check Preferences > JavaScript to confirm that Acrobat JavaScript is enabled.




