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

Bookmark every Second page from an Array

New Here ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

We have some buildings that used to require a one page inspection sheet to be filled out per month.

My previous JavaScript built an array of all our buildings, and whenever one didn't participate, I just "commented" it out of the array before running the JavaScript to bookmark all the pages that did participate.

After they added a second sheet to this inspection, I tried to retrieve the buildings from that array to bookmark every SECOND page (for example, pages 1, 3, 5, 7, etc.). Although it works, the JavaScript also duplicates that same bookmark with another one tagged "undefined."

Could somebody point out my error?

/* Create Bookmarks */

//

// Bookmarks every OTHER page of this document from a defined Array.

//

// Define the Array named aBookmarks.

aBookmarks = new Array(

"Building 01",

"Building 02",

"Building 03",

"Building 04",

"Building 05",

"Building 06",

"Building 07",

"Building 08",

"Building 09",

"Building 10",

"Building 11",

"Building 12",

"Building 13",

"Building 14",

"Building 15",

"Building 16");

// Book every SECOND page from the above array.

var root = this.bookmarkRoot;

// i = Consecutive order of the array.

// n = Total number of pages.

// p = Consecutive order of the pages being bookmarked.

var n = this.numPages;

try {

    for (var i = 0; i < n; i){

    for (var p = 0; p < n; p){

{

    root.createChild(aBookmarks, "this.pageNum=" + p, p)

    var i = i + 1;

    var p = p + 2

}}}}

// Notify user of possible errors.

catch(e)

{

app.alert("Processing error: "+e)

}

TOPICS
Acrobat SDK and JavaScript , Windows

Views

398

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 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

Why do you use 2 for loops?

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 ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

When I try to combine the two variables into a single for loop, it gets stuck inside an endlessly repeating loop that freezes up the application.

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 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

Use one for loop with one variable.

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 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

Use this code (keep the aBookmarks definition, of course):

var root = this.bookmarkRoot;

for (var i=0; i<aBookmarks.length; i++) {

    root.createChild({cName: aBookmarks, cExpr: "this.pageNum=" + (i*2), nIndex: i});

}

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 ,
Feb 07, 2019 Feb 07, 2019

Copy link to clipboard

Copied

LATEST

Thank you so much!

I noticed that I did have to add one extra } in line 4.

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