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

Page Numbers with Spawn Pages

Explorer ,
Feb 21, 2018 Feb 21, 2018

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
3.1K
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

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.

Translate
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.

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

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.

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

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>

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

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.

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

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.

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

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");

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

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