To sequentially number form fields across multiple pages in Adobe Acrobat Pro DC, use the field's "Name" property combined with a custom calculation script. By setting the initial field name to include a base index and appending the page number via JavaScript, you can create unique identifiers that automatically update as users navigate through the document, ensuring accurate data organization without manual entry errors.
Understanding PDF Form Field Naming
The foundation of sequential numbering lies in how Acrobat identifies fields. Every interactive element in a PDF has a unique Name property. Unlike display names which are visible to the user, the internal name is used by scripts and validation rules. When creating a form, it is crucial to establish a consistent naming convention. For example, using a prefix like Page_ followed by a number helps distinguish these fields from others in the document. This structure allows JavaScript to parse the field identity programmatically, which is essential for automating tasks across different pages.
If you attempt to iterate through all fields using generic loops, you may encounter unreliable ordering because the tab order does not always match the logical reading order. Therefore, relying on specific field names or explicit references is safer than trying to guess the position of a field in the document tree. This approach prevents errors where scripts might target the wrong input box, leading to misplaced numbers or calculation failures.
Setting Up the Base Fields
Begin by designing your form layout. Place a text field on the first page where the sequence number should appear. In the Properties panel, under the General tab, set the field name. Avoid spaces or special characters in the name to ensure compatibility with JavaScript. A good practice is to name this field SeqNum_Page1. You will replicate this field on subsequent pages, but you must change the suffix to reflect the page number, such as SeqNum_Page2, SeqNum_Page3, and so on. This manual setup creates the anchor points for your automation logic.
Implementing the Calculation Script
To automate the numbering, you need a script that runs when the document opens or when a field changes. The most robust method involves a Document-Level JavaScript. Go to Tools > JavaScript > Set Document Actions. Select Document Will Open from the dropdown menu. This ensures the numbering logic is applied before the user interacts with the form. Inside the editor, you can define a function that iterates through your specific fields.
However, a simpler and more direct approach for sequential numbering is to use the this.pageNum property within the field itself. If you place a calculation script in each numbered field, it can reference its own location. The script retrieves the current page number and formats it into the desired sequence. This method bypasses the complexity of global field iteration, which is often prone to errors if the form structure changes. It also ensures that if a user jumps to page 5, the number reflects page 5 immediately.
Writing the JavaScript Code
Enter the following code into the Custom Calculation Script of your first numbered field. Note that we use event.target to refer to the field executing the script, avoiding the undefined this context error common in document-level scripts when not properly scoped.
// Get the current page number (0-indexed)
var pageNum = this.pageNum + 1;
// Format the number with leading zeros if needed
var seqNumber = String(pageNum).padStart(3, '0');
// Set the value of the field
event.value = "SEQ-" + seqNumber;
This script calculates the page number dynamically. The padStart method ensures that single-digit pages appear as 001 instead of 1, maintaining visual consistency. By applying this same script to all corresponding fields across your pages, each field will automatically display its correct sequential identifier based on its physical location in the PDF.
Handling Dependencies and Validation
Once the numbering is active, you may want to lock these fields to prevent accidental editing. In the field properties, go to the Appearance tab and check Read Only. This protects the integrity of the sequence. Additionally, consider adding validation rules to other fields that depend on this sequence. For instance, if a signature field requires the preceding number to be filled, you can add a validation script that checks for non-empty values.
It is important to test the form thoroughly. Navigate between pages rapidly to ensure the numbers update correctly. Check edge cases, such as deleting a page or merging two PDFs, as these actions can shift page numbers and potentially break the sequence. If you merge documents, you may need to re-run a batch processing script to reset all field values based on the new page indices.
Troubleshooting Common Issues
If the numbers do not appear, verify that JavaScript is enabled in the reader preferences. Users running the form in a browser or mobile app may have restricted scripting capabilities. Ensure the PDF is saved with the Enable Additional Features option checked in Acrobat Pro. This embeds the necessary JavaScript engine into the file. Without this feature, the calculation scripts will remain inert, and the fields will show blank values regardless of the code quality.
Frequently Asked Questions
Can I use this method in Adobe Reader?
Yes, provided the PDF was saved with full interactivity features enabled. Standard free readers support basic form filling, but complex JavaScript calculations require the document to be optimized for extended features. Always test the final PDF in the intended viewer environment to confirm compatibility.
What happens if I delete a page after numbering?
Deleting a page shifts the pageNum index for all subsequent pages. Since the script uses dynamic page numbers, the fields on remaining pages will automatically update their displayed values. However, any external data linked to the old static numbers may become misaligned, so review dependent fields after structural changes.
How do I handle non-sequential page gaps?
If your form has blank pages or skipped sections, the sequential number will still increment by one for every physical page. To skip numbers, you would need to modify the script to check for specific field existence or use a counter variable stored in a hidden field, rather than relying solely on this.pageNum.
Is there a way to auto-increment based on user input?
Yes, instead of using page numbers, you can link the field value to another input field. For example, if a user enters an ID in a previous field, you can reference that field's value in the calculation script. This allows for custom sequences based on data rather than document structure, offering greater flexibility for complex workflows.
Why did my previous script fail with 'undefined' errors?
This usually occurs when using this in a document-level action without a proper object context. In field-specific scripts, this refers to the field itself, which is valid. In document actions, you must explicitly reference the document object or use event.target to access the current field safely. Always scope your variables to avoid global conflicts.