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

Page Numbers with Spawn Pages

Explorer ,
Feb 21, 2018 Feb 21, 2018

Copy link to clipboard

Copied

Hello,

I have a 1 page PDF form which I have set to be a template. I have added in page numbers up in the top right of the header (page 1 of n). I have also added a button that when pressed will execute the following code:

var t = this.getTemplate("Template");

t.spawn(event.target.page + 1, true, false);

The problem is when the button to duplicate the pages is pressed the page numbering remains "Page 1 of 1" on both of the pages.

Is there some code I can add to the button that will tell the page numbering to update after I have added the button is pressed and the new page added?

Cheers,

Seb.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.3K

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 , Feb 21, 2018 Feb 21, 2018

You'll need to use fields for that.

They can have the following calculation script:

event.value = "Page " + (event.target.page+1) + " of " + this.numPages;

And after spawning the pages call the calculateNow method to update them.

Votes

Translate

Translate
Community Expert ,
Feb 21, 2018 Feb 21, 2018

Copy link to clipboard

Copied

You'll need to use fields for that.

They can have the following calculation script:

event.value = "Page " + (event.target.page+1) + " of " + this.numPages;

And after spawning the pages call the calculateNow method to update them.

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
Explorer ,
Feb 21, 2018 Feb 21, 2018

Copy link to clipboard

Copied

Hi Try,

That's worked quite nicely. It actually works now and also looks identical to the header after I made the field read only so that's good.

Just wondering what the point of the calculateNow method was as it currently works without using this bit of code.

Thanks mate.

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 ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

I was not sure if the spawning command will cause the calculation events to

trigger, so I thought it's better to force it, to make sure they present

the correct value.

If you see it's not needed you can remove it, of course.

On 22 February 2018 at 00:52, sebastianb99835257 <forums_noreply@adobe.com>

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
Explorer ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

Hi Try,

I have another related question to spawn pages.

When spawning pages all of my field names now have "P4.Template." in front of them.

This means that some of my JavaScript doesn't work, such as:

var Zoomz = getField("Zoom_In_3");

Is there a way to for example set n = to the total number of pages minus 1. Then change my bit of code to be something like:

var Zoomz = getField("P"n".Template.Zoom_In_3");

Cheers,

Seb.

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 ,
Feb 23, 2018 Feb 23, 2018

Copy link to clipboard

Copied

No. The name of the spawned fields is determined by the template name, the page number and the original field name.

So it's predictable, but it's not changeable. You will need to modify your code to work with it.

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
Explorer ,
Feb 25, 2018 Feb 25, 2018

Copy link to clipboard

Copied

I understand the way in which the template pages and fields are generated and that it's not changeable. I was basically asking if there is a way to set a dynamic variable (in this case what the page number is) and then reference it within the getField(...).

For example this is the hard coded field name:

var Zoomz = getField("P4.Template.Zoom_In_3");

I want to set the number in the P4 to be a variable and then reference the field that way. I'm just not sure how to use variables inside field names..

Something like this but I'm not sure of proper syntax or if this is even possible:

var Count = this.numPages;

var Zoomz = getField("P"Count".Template.Zoom_In_3");

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 ,
Feb 25, 2018 Feb 25, 2018

Copy link to clipboard

Copied

LATEST

Ah, sure, that's possible like this:

"P"+Count+".Template.Zoom_In_3"

The plus-operator can be used to concatenate strings, including the values of variables, one to each other.

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