Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Form fields to show page numbers dynamically?

New Here ,
Jan 27, 2020 Jan 27, 2020

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. 

TOPICS
Acrobat SDK and JavaScript
13.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2021 Jun 29, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 29, 2021 Jun 29, 2021

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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2021 Jun 29, 2021

Yes, that's possible, but then it won't work in Reader...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 29, 2021 Jun 29, 2021

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 29, 2021 Jun 29, 2021

Use the way I suggested. Just set the bRename parameter of the spawn method to true and add a call to calculateNow afterwards.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 29, 2021 Jun 29, 2021

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2021 Jun 30, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 02, 2021 Jul 02, 2021

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 02, 2021 Jul 02, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2021 Jul 02, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 02, 2021 Jul 02, 2021

Here's an example file I created that demonstrates it: https://drive.google.com/file/d/155FZq6BEyAe4BQ9Qpk2Izp_5Le_0hpKP/view?usp=sharing

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 05, 2021 Jul 05, 2021
LATEST

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!

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines