Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Just that line. If you see what you described it means your fields are not unique, though. The -1 indicates there's a field with the same name on a hidden template page.
Copy link to clipboard
Copied
Ah, that makes sense! Is there a way that the checkbox could simply make the template appear rather than spawing it? I feel like that will make things less complicated.
Not all of the templates need to be used every time, but when I only call a few of them I want the page numbers to line up with the rest of the document.
Thanks for all your help, I'm very new with this.
Copy link to clipboard
Copied
Yes, that's possible, but then it won't work in Reader...
Copy link to clipboard
Copied
Ah, ok. So spawning them is the best way to go. Is there a simple way to number the pages? Or maybe just a way to number all the pages at the end?
Copy link to clipboard
Copied
Use the way I suggested. Just set the bRename parameter of the spawn method to true and add a call to calculateNow afterwards.
Copy link to clipboard
Copied
Thank you! Is there a way to stop certain fields from renaming? I have a footer at the bottom that shows the building name after then enter that information on the first page, but if it is called P5 Building Name it doesn't work. Can I use a getField to retrieve the name somehow?
Copy link to clipboard
Copied
No, it's either all of them, or none. However, you can access the new fields and give them the desired value, sure. The names of the fields on the spawned pages are predictable. They included the page number, the template name and the original field name.
Copy link to clipboard
Copied
So if the spawned page knows what page number it is (it is included in the generated field names) why isn't it more simple to autofill the page number?
Copy link to clipboard
Copied
Is there a way to create a button that the user simply clicks at the end which numbers the pages? This is all getting so complicated for some page numbers that count up 1 by 1
Copy link to clipboard
Copied
It's really not that complicated. All you need is to follow my instructions and it will work.
It's one line of code for the calculations of the page number fields, one small tweak to the spawn method, and one additional line of code afterwards.
Copy link to clipboard
Copied
Here's an example file I created that demonstrates it: https://drive.google.com/file/d/155FZq6BEyAe4BQ9Qpk2Izp_5Le_0hpKP/view?usp=sharing
Copy link to clipboard
Copied
Ok, thank you! Work has ramped up a fair bit, but when I get time I'll try to use these resources to tackle the problem. Thank you!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more