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

Question about page numbers for a hidden template.

New Here ,
Apr 08, 2019 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?

TOPICS
Acrobat SDK and JavaScript

Views

458

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
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 09, 2019 Apr 09, 2019

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.

Votes

Translate

Translate
Community Expert ,
Apr 09, 2019 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.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
New Here ,
Apr 10, 2019 Apr 10, 2019

Copy link to clipboard

Copied

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

Votes

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
community guidelines
New Here ,
Apr 10, 2019 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.

Votes

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
community guidelines
Community Expert ,
Apr 10, 2019 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?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
New Here ,
Apr 10, 2019 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();

Votes

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
community guidelines
Community Expert ,
Apr 10, 2019 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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
New Here ,
Apr 11, 2019 Apr 11, 2019

Copy link to clipboard

Copied

LATEST

Thom,

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

Votes

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
community guidelines