Question about page numbers for a hidden template.

New Here ,
Apr 08, 2019

Copy link to clipboard

Copied

I have a two page form, created in Acrobat DC, that contains a table on the second page for entering information about purchase order line items.  If the user needs additional lines I have included a java code button on page 2 to open a hidden template page.  The user can continue to add more pages as needed.  Is there a way to have these added pages sequentially numbered (beginning with page 3) at the bottom center of the pages?

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

Yes,  Add a readonly form field to the bottom of the template page for the page number.  You can either add a calculation script to the field for setting the number:

event.value = event.target.page + 1;

or add code to your script for spawning the page. This is actually preferable because calculations can become problematic if there are lot of them on the PDF.

TOPICS
Acrobat SDK and JavaScript

Views

117

Likes

Translate

Translate

Report

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

Question about page numbers for a hidden template.

New Here ,
Apr 08, 2019

Copy link to clipboard

Copied

I have a two page form, created in Acrobat DC, that contains a table on the second page for entering information about purchase order line items.  If the user needs additional lines I have included a java code button on page 2 to open a hidden template page.  The user can continue to add more pages as needed.  Is there a way to have these added pages sequentially numbered (beginning with page 3) at the bottom center of the pages?

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

Yes,  Add a readonly form field to the bottom of the template page for the page number.  You can either add a calculation script to the field for setting the number:

event.value = event.target.page + 1;

or add code to your script for spawning the page. This is actually preferable because calculations can become problematic if there are lot of them on the PDF.

TOPICS
Acrobat SDK and JavaScript

Views

118

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 08, 2019 0
Adobe Community Professional ,
Apr 09, 2019

Copy link to clipboard

Copied

Yes,  Add a readonly form field to the bottom of the template page for the page number.  You can either add a calculation script to the field for setting the number:

event.value = event.target.page + 1;

or add code to your script for spawning the page. This is actually preferable because calculations can become problematic if there are lot of them on the PDF.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 09, 2019 0
New Here ,
Apr 10, 2019

Copy link to clipboard

Copied

Thom, thank you.  I'll give that a try.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2019 0
New Here ,
Apr 10, 2019

Copy link to clipboard

Copied

Thom,

Using the script you provided at the bottom of the template, when I clicked on my add a page button on page 2, the template page opened and showed page 3.  However, when I clicked on my add a page button on page 2 to add page 4, the template opened and showed page 0.  I'm therefore guessing that your second suggestion of adding code to the script in my add a page button is what I need to do.  Can you suggest the code that I need to add?  Or am I not understanding your recommendation.

Thanks.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2019 0
Adobe Community Professional ,
Apr 10, 2019

Copy link to clipboard

Copied

The page number code shows the number of the page on which the field is on, and since it is a calculation, it is re-run every time any field on the form changes. That 0 should change as soon an anything else on the form changes.  The cool thing about this code is it works if you insert pages before the new template page.  It could be that nothing yet has changed on the form.  So you could solve this by adding this code to the end of you spawn script.

this.calculateNow();

But, in order to add the number at spawn time I'll need to see your code from the "Add Page" button. Can you post it?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2019 1
New Here ,
Apr 10, 2019

Copy link to clipboard

Copied

The "Add Page" code on page 2 is:

var a = this.getTemplate ("Extra Line Items"); a.spawn();

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2019 0
Adobe Community Professional ,
Apr 10, 2019

Copy link to clipboard

Copied

This code overlays the template on the first page.  Take a look at the reference entry for the template.spawn function:

Acrobat DC SDK Documentation

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 10, 2019 1
New Here ,
Apr 11, 2019

Copy link to clipboard

Copied

Thom,

I added the calculate now code as you suggested and the page numbering is working fine.  Thanks so much.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 11, 2019 0