Skip to main content
Participating Frequently
January 27, 2020
Question

Form fields to show page numbers dynamically?

  • January 27, 2020
  • 2 replies
  • 13054 views

I need to be able to use form fields to indicate "Page X of Y". I know there's an option to do this in the document footer, but it won't work for this process because the documents are being aggregated in another system and it needs to be able to combine docs and have the page numbering change to match. If you use Acrobat's footers, combining two three-page documents gives you a six page document with page numbers 1/3, 2/3, 3/3, 1/3, 2/3, 3/3 instead of 1/6, 2/6, etc.

 

The question: How do I set it up so each page has a field, "PageNo", that indicates the current page number, and another field next to it, "NoPages," that contains the current number of pages in the document? These fields have to be able to update dynamically on document open as the documents are combined or split in a third party system.

 

The main problem I've run into: Any field with the same name as another field is functionally a copy of the original field and mirrors that field's contents. So you end up with five pages marked "Page 1 of 5." I can't give the fields unique names on each page, either, because the document combining happens outside of Acrobat and could be any combination of forms being compiled into various reports. I also don't have access to the system controlling this process, it's a black box.

 

I'm hoping there's some document-level script out there that can be set up to run when the merged document is opened to update the page numbers and total number of pages, but I don't know anywhere close to enough about JavaScript to come up with it on my own. I've also not run across any snippets of code floating around that handle this precise issue. If anyone can offer me any insight it would be greatly appreciated, I'm at the end of my rope with this one. 

This topic has been closed for replies.

2 replies

JR Boulay
Community Expert
Community Expert
January 27, 2020

I read too fast… 😉

 

Place this JavaScript as a calculation script in text fields:

 

var pnum = this.pageNum+1;
var numpag = this.numPages
event.value = pnum + " / " + numpag;

 

As any calculation script, it requires something to happen to be triggered. So you need to do something with form fields to update pages numbers (eg: Reset).

Acrobate du PDF, InDesigner et Photoshopographe
Known Participant
September 30, 2020

I did the above calculation JR and when I deleted a page it did not change the page numbers i.e. I had pages 1 of 3 and I deleted page 3 and the first page still says Page 1 of 3.

Known Participant
October 5, 2020

"As any calculation script, it requires something to happen to be triggered. So you need to do something with form fields to update pages numbers (eg: Reset)."


I am still confused with your response. I need to insert a form field and when I add or delet pages of pdf I need page numbers to update automatically 

Dave Creamer of IDEAS
Community Expert
Community Expert
January 27, 2020

You could just remove and update the footer as needed. I would create an Action for this but it's only a couple of steps.

Also, I googled "javascript page numbering in pdf" and came up with a number of options, including:

https://asserttrue.blogspot.com/2011/04/script-for-putting-page-numbers-on-pdf.html

Note: I have not tested this code.

David Creamer: Community Expert (ACI and ACE 1995-2023)
JR Boulay
Community Expert
Community Expert
January 27, 2020

Using form fields to add pages number is old school an really time consuming:

😉

 

Acrobate du PDF, InDesigner et Photoshopographe
Participating Frequently
January 27, 2020

It is, yes. But for the reasons outlined in my original post, it's the only way to do the job in this instance.