Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Problem is I already had them with different field names. I even changed the fields names to something else and they still gave me the same answers. Any other ideas? Do you have any other coding that would work better in this situation?
Copy link to clipboard
Copied
I'll need to see the actual file to help you further with this issue.
Copy link to clipboard
Copied
How do I get you the file? I thought I had seen a link before, but I can't find it now.
I've removed some of the content just to make the file smaller and easier to go through. The templates with the page numbering code are on templates 1K1-2, 1K1-3 & 1K1-4. To see the page nums on the actual page, choose:
Field Drop.NumKids -- choose "1"
Then field 1.ReportType -- choose "Permanency Report"
I hope you find what's going on. Sorry if my organization of the file is a bit off.
Copy link to clipboard
Copied
You can attach it to the original message using the tiny paperclip icon at the bottom when you edit it, or upload it to a file-sharing website (like Dropbox, Google Drive, Adobe Cloud, etc.), generate a share link and then post it here.
You can also email it to me privately to [try6767 at gmail.com], if you prefer.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
You have to specify the bRename parameter of the spawn command to true. I had assumed that's what you were doing... If it's not, then that is certainly the cause for this issue. In addition you would need to call the calculateNow method after spawning the pages, to update the values of the fields.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Not anything obvious, no... Try running the code one line at a time from the JS Console, and see if it's still happening.