These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Automating Bookmarks Error

JNorris
Registered: Sep 7 2011
Posts: 31
Answered

I've run into a problem using the Automating Bookmark tutorial's script, which I'll post here:
 
function FindBookmarkByName(oBkMkParent,cFindName,nInc)
{
if(nInc == null)
nInc = [1];
else if(typeof(nInc) == "number")
nInc = [nInc];
 
var aBkMks = oBkMkParent.children;
var oRtn = null;
if(aBkMks != null)
{
for(var i=0;i

var aSchedNames = [ "....Choices in here...."];
 
var cRtn = app.popUpMenu.apply(app, aSchedNames);
if(cRtn != null)
{
app.execMenuItem("NewBookmark");
app.execMenuItem("NewBookmark");
 
var oBkMk = FindBookmarkByName(this.bookmarkRoot,"Untitled");
if(oBkMk != null)
oBkMk.name = cRtn;
 
var oBkMkEx = FindBookmarkByName(this.bookmarkRoot,"Untitled");
if(oBkMkEx != null)
oBkMkEx.remove();
}
 
The problem is that this runs successful only for a few bookmarks, then the bookmarks begin to be named Untitled. If I double click on Untitled then the name will change but that's an extra step that obviously was not part of the design. Any suggestions?

My Product Information:
Acrobat Pro 10.0, Windows
JNorris
Registered: Sep 7 2011
Posts: 31
..Hmm...I'm having trouble seeing the whole function on my post so here's the link if you can't see it:

http://acrobatusers.com/tutorials/2008/10/auto_bookmark_creation
try67
Online
Expert
Registered: Oct 30 2008
Posts: 2401
Any reason why you're creating new bookmarks using app.execMenuItem("NewBookmark") instead of the createChild() method?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

JNorris
Registered: Sep 7 2011
Posts: 31
Quote from Tutorial:

"The most obvious method is the bookmark.createChild() function. This function creates a new bookmark underneath an existing bookmark. All PDF documents, even ones with no bookmarks at all, have an invisible top-level bookmark called doc.bookmarkRoot. So we don’t need to worry about creating the first bookmark in the PDF, bookmark.createChild() works for creating any bookmark we might need. This function is easy to use and creates the bookmark in exactly the position it needs to be in. The downside to using this function is that it can only create bookmarks that execute JavaScript. None of the other bookmark actions can be set from an automation script. This works fine if we want our new bookmark to run a script, but it doesn’t help for making position-independent, page-navigation bookmarks."

If you think there is a better way, please share :) As I wrote, the tutorial's method seems flawed for multiple uses.
try67
Online
Expert
Registered: Oct 30 2008
Posts: 2401
I don't understand. If the tutorial (which one, by the way?) recommends using createChild(), as I did, why did you use the menu item?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

JNorris
Registered: Sep 7 2011
Posts: 31
I posted the url to the tutorial in my 2nd post. Here it is again: http://acrobatusers.com/tutorials/2008/10/auto_bookmark_creation . It does not recommend createChild because it doesn't help for position-independent page-navigation. It does not contain the js Go to page, or so it says or if I'm mistaken. If you do have an alternative solution using createChild please share.

Edit: I've been looking around and haven't been able to find a function using createChild() that allows for the destination to be set based on current page selection (that's why I use the New Bookmark menu item).
try67
Online
Expert
Registered: Oct 30 2008
Posts: 2401
You can use the cExpr parameter of createChild to set the action of the new bookmark you've created to whatever JS code you want. For example, this code will create 3 bookmarks that go to pages 1 to 3:
  1. this.bookmarkRoot.createChild({cName:"Page 1", cExpr:"this.pageNum = 0", nIndex: 0})
  2. this.bookmarkRoot.createChild({cName:"Page 2", cExpr:"this.pageNum = 1", nIndex: 1})
  3. this.bookmarkRoot.createChild({cName:"Page 3", cExpr:"this.pageNum = 2", nIndex: 2})

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

JNorris
Registered: Sep 7 2011
Posts: 31
Okay, this will work; however, I need the bookmark to point to the page that is selected when the action is run. How would I go about changing the cExpr to accomplish this?

If my explanation was confusing, here is a breakdown:
1)user selects option (coding already done)
2)page that is currently being viewed is bookmarked with destination of said page


Edit: Current Code fyi:
this.bookmarkRoot.createChild({cName:cRtn, cExpr:"this.pageNum=???", nIndex: this.numPages-1})

(cRtn is a variable previously defined)
try67
Online
Expert
Registered: Oct 30 2008
Posts: 2401
Accepted Answer
cExpr: "this.pageNum=" + this.pageNum

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

JNorris
Registered: Sep 7 2011
Posts: 31
This works great. Thank you.