Skip to main content
toddr14813053
Inspiring
September 23, 2020
Question

Dynamic Page Number - Calcuation

  • September 23, 2020
  • 1 reply
  • 1454 views

I have been trying to set up dynamic page numbering for a fillable form I have created. There are several fields on the form that cause pages to either spawn or delete, so I am wanting the script to auto update the page numbers and the total number of pages. I have been researching this for several days online and have found several different scripts and none of them seem to work properly. This is the one that has made the most headway.

 

event.value = "Page " + (event.target.page + 1) + " of " + (this.numPages);

 

The problem I am running into is that when I use the event.target.page I get weird answers like "-1,21 of 4" then "-1,31 of 4" on the next page, etc. Does anyone know why the form is calculating this way? The number is increasing, I guess, on each page and the total number of pages is correct, but that number formatting is wrong.

 

I have also tried this variation:

 

event.value = "Page " + (this.pageNum +1) + " of  " + (this.numPages);

 

That script just gives me "Page 1 of 4" on every page. The total number of pages is correct, but obviously the current page number is not.

 

Thoughts?

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
September 23, 2020

This happens when you have multiple fields with the same name on different pages. In that case the page property returns an array of the page numbers, like [0, 1] if there's one field on page 1 and another on page 2, for example.

Each field must have a unique name if you want this script to work.

toddr14813053
Inspiring
October 13, 2020

Try6767,

 

I think I may have found the cause of the problem, but I still can't find a solution. I found this completely by accident, but when the form spawns the template page, it is also duplicating the page numbering fields so that they show as duplicate fields. So before the spawn I have a PgNum1 and a PgNum2, etc but after the spawn, I now have 2 of each page number field even though there is only one template that has those specific field names and I have only spawned the page once. Hopefully that makes sense. Now the question is what can we do to avoid this field name duplication? Is it possible to have those fields rename to something other than what is on the template when they spawn?

 

Thoughts?

try67
Community Expert
Community Expert
October 13, 2020

Ok, so I updated the code as follows:

 

else if (event.value == "Permanency Report") {

 

var expTplt1 = getTemplate("1KMain");

expTplt1.spawn({nPage: this.numPages, bRename: true, bOverlay: false});

var expTplt2 = getTemplate("1K1-2");

expTplt2.spawn({nPage: this.numPages, bRename: true, bOverlay: false});

var expTplt3 = getTemplate("1K1-3");

expTplt3.spawn({nPage: this.numPages, bRename: true, bOverlay: false});

var expTplt4 = getTemplate("1K1-4");

expTplt4.spawn({nPage: this.numPages, bRename: true, bOverlay: false});

 

this.deletePages(0);

this.pageNum = 0; }

 

New problem now, though -- everytime I try to choose any option that uses this code, Acrobat crashes so I don't know if this works or not. Is there anything in this new code that would cause it to crash?


Not anything obvious, no... Try running the code one line at a time from the JS Console, and see if it's still happening.