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

Give a number page to a template

New Here ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Hi everyone !

i'am usign acrobat DC (15) on windows.

I have pages spawning when a button is clicked. I would like to display dynamically the page number of a spawned page. In other words, my document has initailly 1 page ( with 8 templates), when the user decides to spawn a page or more, i have a little "blank space" where i would like to display page number.

i am a newbie !!!

thx for evertyhing 😃

TOPICS
Acrobat SDK and JavaScript , Windows

Views

854

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 ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Add text fields for the page numbers to the templates.

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 ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

thx !

but the pages could be spawned in any order, so inside the first page, the number of page should change, et depending on which pages will be spawned, the number should also appear in the pages spawned.

For example,

First page : 1/1

then,template page A and template page B are spawned ( the order could change)

so

the firest page 1/3

and template page A : page 2/3

and template page B : page 3/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 ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

After spawning the page you must set the value of the text field.

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 ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

can i have a little bit of code ?=) thx

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
Engaged ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Post the code for your button and we will update it with what's missing

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 ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

here it is :

// get the value from the dropdown control

var sel = this.getField("liste_qualif").value;

// determine the template name

var templateName = "";

switch (sel) {

  case 1: templateName = "CRI";

    break;

  case 2: templateName = "FI";

    break;

  case 3: templateName = "FTI de FTI";

    break;

    case 4: templateName = "FTI";

    break;

    case 5: templateName = "IRI";

    break;

    case 6: templateName = "MCCI";

    break;

    case 7: templateName = "SFI";

    break;

    case 8: templateName = "STI";

    break;

    case 9: templateName = "TRI";

    break;

}

// if we have a template name, spawn the template

if (templateName != "") {

  var t = this.getTemplate(templateName);

  t.spawn();

}

//pop up for the user

var message = app.alert("Vous avez sélectionné une qualification d'instructeur \n\n"+"La page concernant la qualification vient d'apparaître à la fin du document",1);

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
Engaged ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Add a field at the bottom of each pages and each template.

Put this in the calulate script:

event.value = "Page "+this.pageNum+" / "+this.numPages

by the way, you do not have to put your alert inside a variable to trigger it ;o)

//pop up for the user

var message = app.alert("Vous avez sélectionné une qualification d'instructeur \n\n"+"La page concernant la qualification vient d'apparaître à la fin du document",1)

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
Engaged ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

Also, I think the switch statement is not necessary.  You could use those abreviations directly as export values right from your dropdown menu.

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 ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

thx !!!! for the tips and advice ... 😃

however, i ve putted this code in a the main page and 2 templates ( just to try if it works ) ... some problems appear :

The " this.pageNum" does'nt seem to work, because it's blocked at 0, and instead of incrementing the total number of page, it decreases.

For example, page 1 : 0/1,

after spawning a page : page template A : 0/1 AND page 1 : 0/2

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 ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

actually, only the last decreases of "1"

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 ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

you can find my file here : 00Formlic_Interactif_js_v5.pdf - Google Drive

you need to select : either TRI or STI in the dropdown list and then validate with the button just on the right. It's in french ...

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
Engaged ,
May 09, 2018 May 09, 2018

Copy link to clipboard

Copied

I'm french also, lol

pageNum is 0-based also so you have to give it an increment

event.value = "Page "+(this.pageNum+1)+" / "+this.numPages

and since this script is a calculate script (and the spawning of a template doesn't trigger the calculate event), you need to trigger it manually.

put this:

this.calculateNow()

right after the spawn() function in the button

Othewise, it would have triggered as soon as you enter whatever in whaterver field.

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 ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

Thx !!! ( j'étais en jour off, c'est pour a que j'ai mis du temps à répondre ) ...

Now the total amount of page is OK 😃

but ... i have still a little problem, it's still block at 0 for the current page, the number doesnt incremente ?

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 ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

i need to find a scirpt, which allow to take into consideration whatever order the pages will be spawed and give the the right number

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 ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

Bonjour.

Une réponse claire et en français se trouve ici : https://abracadabrapdf.net/forum/index.php/topic,3224.msg18951.html#msg18951

Enjoy.

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 ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

Merci !

Mais cela ne marche que pour les pages ayant été DUPLIQUEES et SPAWNED ( simultanément) =(

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
Engaged ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

What do you mean by "take into consideration whatever order the pages will be spawed"?  Doesn't spawned pages append to the end of the document?  Therefore, their order in the document is the same as the order they were spawned?

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 ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

Yes, i meant that ...

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
Engaged ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

The script I wrote, And the link provided by @JR_Boulay , they do just that.

My script:

this.pageNum() method returns the position of the page in the document as a 0-Based index.  Therefore, this.pageNum()+1 is the number of the page.

@JR_Boulay's script:

the "page" property of the field object (event.target.page) as described in the post returnes the same thing but will return an array of integer if there is more than one occurence of the same field, based on the order they were created.

I tested my script in your document.  It works fine except for some reason, the calculateNow() method doesn't trigger fast enough for the fields to update.  It updates as soon as a value is commited anywhere in the document (because it is a calulate script)

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
Engaged ,
May 11, 2018 May 11, 2018

Copy link to clipboard

Copied

Try the solution posted by JR_Boulay.  But for that to work, the field of your main page must be different from the on in your templates.  Whenever I change the script in "Text27", it changes acoordingly in P1.TRI.Text27.      Since both scripts are slightly different, you need to independant fields.

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 ,
May 14, 2018 May 14, 2018

Copy link to clipboard

Copied

LATEST

I use a trick: I never spawn/add one page somewhere in a document: first I delete all pages and I re-spawn all pages in their final order, starting by the end. This is usefull for small documents, less than 50 pages, since you never have to manage a relative pages order.

the calculateNow() method doesn't trigger fast enough

Add this script at the beginning of the script:

this.calculate = false;

And add this one at the end :

this.calculate = true;

this.calculateNow();

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