Bookmark methods

createChild

execute

insertChild

remove

setAction

createChild

5.0

D 

 

X 

Creates a new child bookmark at the specified location.

See also the children property and the insertChild and remove methods.

Parameters

cName 

The name of the bookmark that the user sees in the navigation panel.

cExpr 

(optional) An expression to be evaluated whenever the user clicks the bookmark. It is equivalent to creating a bookmark with a JavaScript action, as described in the PDF Reference. The default is no expression.

nIndex 

(optional) The 0-based index into the children array of the bookmark at which to create the new child. The default is 0.

Example

Create a bookmark at the top of the bookmark panel that takes you to the next page in the document.

   this.bookmarkRoot.createChild("Next Page", "this.pageNum++");

execute

5.0

 

 

 

Executes the action associated with this bookmark. This can have a variety of behaviors. See the PDF Reference for a list of common action types. See also the createChild method.

Example

Implement a simple search of the bookmarks. If successful, the action associated with the bookmark is executed.

   // Document-level or folder-level JavaScript.

   function searchBookmarks(bkm, nLevel, bkmName)

   {

      if ( bkm.name == bkmName ) return bkm;

      if (bkm.children != null) {

         for (var i = 0; i < bkm.children.length; i++)

         {

            var bkMark = searchBookmarks(

               bkm.children[i], nLevel + 1, bkmName);

            if ( bkMark != null ) break;

         }

         return bkMark;

      }

      return null;

   }

   // Redefine this function for a more sophisticated compare.

   function bmkCompare( name1, name2 )

   {

         return ( name1 == name2 );

   }

The following code initiates the search. This code could be executed as field-level JavaScript or be executed as a menu action.

   var bkmName = app.response({

      cQuestion: "Enter the name of the bookmark to find",

      cTitle: "Bookmark Search and Execute"

   });

   if ( bkmName != null ) {

      var bkm = searchBookmarks(this.bookmarkRoot, 0, bkmName );

      if ( bkm != null ) bkm.execute();

      else app.alert("Bookmark not found");

   }

insertChild

5.0

D 

 

X 

Inserts the specified bookmark as a child of this bookmark. If the bookmark already exists in the bookmark tree, it is unlinked before inserting it back into the tree. In addition, the insertion is checked for circularities and disallowed if one exists. This prevents users from inserting a bookmark as a child or grandchild of itself. See also the children property and the createChild and remove methods.

Parameters

oBookmark 

A bookmark object to add as the child of this bookmark.

nIndex 

(optional) The 0-based index into the children array of the bookmark at which to insert the new child. The default is 0.

Example

Take the first child bookmark and move it to the end of the bookmarks.

   var bm = bookmarkRoot.children[0];

   bookmarkRoot.insertChild(bm, bookmarkRoot.children.length);

remove

5.0

D 

 

X 

Removes the bookmark and all its children from the bookmark tree. See also the children property and the createChild and insertChild methods.

Example

Remove all bookmarks from the document.

   bookmarkRoot.remove();

setAction

6.0

 

 

X 

Sets a JavaScript action for a bookmark.

See also the Doc addRequirement and setPageAction methods and the Field object setAction method.

Note:This method overwrites any action already defined for this bookmark.

Parameters

cScript 

Defines the JavaScript expression that is to be executed whenever the user clicks the bookmark.

Example

Attach an action to the topmost bookmark.

   var bm = bookmarkRoot.children[0]

   bm.setAction("app.beep(0);");