Get PDF Form Field Names by Page Range in Adobe Acrobat
Question details
Find PDF form field names that appear within a specified page range.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A user wants to identify fields on selected PDF pages before populating them with Acrobat JavaScript.
- Observed behavior
- doc.numFields counts fields across the entire document rather than only the selected pages.
Open the PDF in Adobe Acrobat and make sure JavaScript is enabled in Acrobat's Preferences. Identify the first and last pages you want to inspect; the script below accepts the page numbers shown in the document.
Filter PDF Form Fields by Page with Acrobat JavaScript
Use the JavaScript console to collect field names whose page property overlaps the requested range.
Acrobat page indexes are zero-based, so the script converts the displayed page numbers before comparing them. A field's page property can be a number or an array when the field appears on multiple pages.
With the PDF open in Acrobat, open the JavaScript console. On Windows, use Ctrl+J; console availability depends on your Acrobat product and settings.
Paste the following script into the console and replace 2 and 4 with the first and last displayed page numbers you want to include: var doc = this; var firstPage = 2; var lastPage = 4; var names = []; for (var i = 0; i < doc.numFields; i++) { var name = doc.getNthFieldName(i); var field = doc.getField(name); if (!field) continue; var pages = field.page; if (typeof pages === "number") pages = [pages]; if (!pages) continue; for (var j = 0; j < pages.length; j++) { if (pages[j] >= firstPage - 1 && pages[j] <= lastPage - 1) { names.push(name); break; } } } console.println(names.join("\n"));
Select the script in the console and execute it. On Windows, press Ctrl+Enter or the numeric keypad Enter key. Review the printed names and use the names array in your field-population script.

Work with PDF Forms and Office Files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility for an easy transition. Its PDF tools can help you work with forms, but the Acrobat JavaScript filtering method above must be run in Acrobat.

Frequently Asked Questions
Why does doc.numFields include fields outside my page range?
doc.numFields counts fields in the whole PDF. Loop through the names with doc.getNthFieldName(i), retrieve each field with doc.getField(name), and filter by field.page.
Are Acrobat JavaScript page indexes zero-based?
Yes. The first page has index 0, so subtract 1 from the displayed page number before comparing it with field.page.
How do I handle a field that appears on multiple pages?
Check whether field.page is a number or an array. If it is an array, inspect each page index and include the field name when at least one index is in the requested range.
Will the script list each occurrence of a repeated field separately?
No. It adds the field name once when any associated page matches. A field with the same name on multiple pages may have multiple widget instances.




