Automatically Display the Total PDF Page Count in Adobe Acrobat
Question details
Display the total number of pages automatically at the top of a PDF form while retaining page numbers at the bottom.

- Product
- Adobe Acrobat or Adobe LiveCycle Designer
- Device & OS
- not provided
- Scenario
- A PDF form needs a total page count in a top-of-page field alongside existing footer page numbers.
- Observed behavior
- The form should show the current total page count and update it when pages are added or removed.
Check whether the PDF is a standard Acrobat form or a dynamic LiveCycle/XFA form, because they use different scripting models. For an Acrobat form, you need a version of Acrobat that can edit form fields and document JavaScript.
Add an automatic page count field in Adobe Acrobat
Use this method for a standard Acrobat form to populate a text field whenever the PDF opens.
The script reads the document's page count and writes it to a named text field. It does not alter existing footer page numbers.
This method is for standard Acrobat forms, not dynamic LiveCycle/XFA forms. JavaScript must be enabled in the PDF viewer.
Open the PDF in Acrobat and choose All tools > Prepare a form. Add a text field at the top of the page and name it TotalPages.
Open the TotalPages field's Properties and select Read Only on the General tab so users do not accidentally change the displayed value.
Open Acrobat's JavaScript tools and choose Document JavaScripts. Add a script named UpdateTotalPages with this code: var field = this.getField("TotalPages"); if (field) field.value = this.numPages;
Save the PDF, close it, and reopen it in Acrobat. Confirm that the top field shows the total and that the existing footer page numbers remain visible.
After adding or removing pages using Acrobat's Organize pages tool, save, close, and reopen the PDF so the document script runs again.

View and work with PDF documents in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface for working with PDFs and Office files. Its format compatibility makes it easy to move existing documents into your workflow. It does not replace Acrobat's document JavaScript for automatically populating this form field.

Frequently Asked Questions
Will the total update immediately when I add or remove a page?
The document script in this solution runs when the PDF opens. After changing pages in Organize pages, save, close, and reopen the PDF to refresh the field.
Will adding the total page count remove my footer page numbers?
No. Adding the TotalPages form field and document script does not change existing footer page numbers. Check the footer after saving and reopening the PDF.
Why is the total page count field blank?
Check that the field is named TotalPages in Prepare a form, that the document script was saved, and that JavaScript is enabled in the PDF viewer. Then close and reopen the PDF.
Can I use the same script in a dynamic LiveCycle form?
Not necessarily. Dynamic LiveCycle/XFA forms use a different scripting model and can paginate as their layout changes. Use LiveCycle Designer's layout and scripting features for those forms rather than relying on the standard Acrobat form script.




