Page blank of blank, dynamically generating page numbers from spawned pages

New Here ,
Aug 19, 2019 Aug 19, 2019

Copy link to clipboard

Copied

On my template page, I have a field that is a "Page __ of __" field that should auto-populate when the user creates a new template page. The 1st 6 pages of my 12 page file are intro information, and then page 7 is where the first 'add a page' button is, which calls forth the "T1 template", which spawns as page 8. Yet both of these pages have the Page blank of blank.

So to illustrate, page 7 starts with Page 1 of 1. When the user hits the 'add a page' and generates page 8, page 7 should be Page 1 of 2, and page 8 should be Page 2 of 2. Then when they hit the button again on the newest page, page 7 should be Page 1 of 3, page 8 should be Page 2 of 3, and page 9 should be Page 3 of 3, and etc etc.

So the code I have so far for the "add a page" button on page 7 (and this one seems to be working fine as it's a specific increment with non-changing field names) is:

var SpawnPage = this.getTemplate({cName: "T1"});

SpawnPage.spawn({nPage: pageNum + 1, bRename: true, bOverlay: false});

this.pageNum++;

this.getField("Page Number of Number 2").value = 2;

event.target.display = display.hidden;

and then the main code that I have on the template file "add a page" button is:

var SpawnPage = this.getTemplate({cName: "T1"});

SpawnPage.spawn({nPage: pageNum + 1, bRename: true, bOverlay: false});

this.pageNum++;

var prefix = "";

var nameParts = event.target.name.split(".");

if (nameParts.length > 2) {

      prefix = nameParts[0] + "." + nameParts[1] + ".";

}

if (nameParts[0] == "P" + (this.pageNum-1)) {

var f1 = this.getField(prefix + "meta-pagecount1");

var f3 = this.getField("Page Number of Number 2").value = pageNum-5;

var f2 = this.getField(prefix + "meta-pagecount2").value = f3;

};

event.target.display = display.hidden;

As if that wasn't enough, there is also a second section of the pdf (on page 10) that also has the "Page blank of blank", which is totally independent of the first, but that prohibits the ability to simply do a page count from the total number of pages in the document (for part 1) since there is no way to know how many pages the user might create from the second template for part 2. Right now though, I'm only trying to get part 1 working, and I have page 7 working correctly so far, but incorrect numbers are generating upon spawning on the subsequent pages.

Hopefully all of this makes sense.....?:)

TOPICS
Acrobat SDK and JavaScript

Views

69

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
community guidelines
Adobe Community Professional ,
Aug 20, 2019 Aug 20, 2019

Copy link to clipboard

Copied

LATEST

All you need to do is apply the following calculation code to your "Page x of x" fields:

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

And call calculateNow() after spawning the pages.

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