10
Modifying the User Interface
Adding Navigation to PDF Documents
var myRoot = this.bookmarkRoot;
myRoot.createChild("A");
myRoot.createChild({cName: "B", nIndex: 1});
myRoot.createChild({cName: "C", nIndex: 2});
for (var i = 0; i < myRoot.children.length; i++) {
var child = myRoot.children[i];
for (var j = 0; j < 3; j++) {
var name = child.name + j;
child.createChild({cName: name, nIndex: j});
}
}
To print out the hierarchy to the console, you can keep track of levels as shown in the
following code. Note its recursive nature:
function DumpBookmark(bm, nLevel){
// build indents to illustrate the level
var s = "";
for (var i = 0; i < nLevel; i++) s += " ";
// print out the bookmark’s name:
console.println(s + "+-" + bm.name);
// recursively print out the bookmark’s children:
if (bm.children != null)
for (var i = 0; i < bm.children.length; i++)
DumpBookmark(bm.children[i], nLevel+1);
}
// open the console to begin:
console.clear(); console.show();
// recursively print out the bookmark tree
DumpBookmark(this.bookmarkRoot, 0);
174
Acrobat JavaScript Scripting Guide