Is there a way to automatically collapse all bookmarks to the first level?

When we generate user guides consisting of over 600 pages with bookmark set to four levels. I cannot locate an Action option that would collapse all of the bookmarks to the first level without manually closing all levels. I've experienced this issue for years - I'm currently using Acrobat 10 and need a solution due to customer demand.


mheberge


6 Answers

Voted Best Answer

Hi

If you highlight a bookmark, then press shift + / (/ is on the numeric keyboard, the normal / doesnt work).

Failing this, it can be done with a script.

Hope this helps?

Also, to maintain the state of the bookmarks (i.e., collapsed) simply do a Save As and then next time you open the file, all the bookmarks will still be in the collapsed state.


By Sean Mitchell   

Sean - thanks for the quick solution! Is there a way that I can add this to an Action?


mheberge   

Yes, using JavaScript. Have a look at the Bookmark object and especially the open property thereof.
I've create a tool that does exactly that, by the way: Acrobat -- Close/Open All Bookmarks

-------------------------------------
Visit my custom-made PDF scripts website: http://try67.blogspot.com
Contact me personally: try6767@gmail.com


Gilad D (try67)   

Enter this into an Action as an Execute Javascript item. I use it in Acrobat X. I can't take credit for creating it:

function CloseBookmark(bm){ /* Close all bookmarks in a PDF file */ bm.open = false; if (bm.children != null) { // loop to the lowest bookmark for (var i = 0; i < bm.children.length; i++) { CloseBookmark(bm.children[i]); } } return;} CloseBookmark(this.bookmarkRoot);


Randal Cook   

A second attempt to show 14 lines of JavaScript for use in an Execute JavaScript action. Forgive me if it doesn't show properly. That makes it hard to share info or learn about these things.
function CloseBookmark(bm).
{ bm.open = false; if (bm.children != null) for (var i = 0; i < bm.children.length; i++) { CloseBookmark(bm.children[i]); } } return;} CloseBookmark(this.bookmarkRoot);


Randal Cook   

You can try the following user application level folder script to open/close and toggle the bookmarks.

// the bookmark open property is not supported by Reader;
if(app.viewerType != "Reader") { 
function OpenBookmark(bm, bOpen){
/*
Purpose: to Open all the bookmarks in a PDF file

Inputs: bookmark object
        bookmark open property's logical value default is true
          Optionally the bookmark open property can be passed as open or close
          and the funciton will set bOpen parameter tot he correct logical value.   

Returns: logical for sucessful completion of function;

Notes: This function can be placed in the folder level JavaScript 
folder and called through the JavaScript (Debugger) console or called
from a batch process. It could also be added to a PDF as a document
level function and executed on each opening to open all the bookmarks
in the PDF. // example of usage OpenBookMark(this.BookmardRoot, true); This function is recursively calls itself to work through the bookmark tree. author: George Kaiser */ bResult = true; // assumed result for function execution; // check value of bOpen parameter exist if not set to defualt of true; if(typeof bOpen == "undefined") var bOpen = true; if(String(bOpen).toLowerCase().substr(0,1) == "o") bOpen = true; if(String(bOpen).toLowerCase().substr(0,1) == "c") bOpen = false; if(bOpen != true && bOpen != false) { app.alert("bOpen parameter must be either true or flase.\nbOpen = " + bOpen, 0, 0); } try { // set bookmark open property to bOpen value for the current bookmark level; bm.open = bOpen; // loop through all the levels of the bookmarks ; // recursively open the bookmark’s children: if (bm.children != null) { // loop to the lowest bookmark for (var i = 0; i < bm.children.length; i++) { OpenBookmark(bm.children[i], bOpen); } // end for bm.children[i].length } // end if != null } catch (e) { bResult = false; // set return value for failure; app.alert("Open all bookmarks failed.\nBookmark parameter object type: " + typeof bm + "\nbOpem parameter value: " + bOpen, 0, 0); } finally { return bResult; // return process result; } // end try } // end OpenBookmark function } // end viewer type not reader; if(app.viewerType != "Reader") { // the bookmark open property is not supported by Reader; // add menuitem for Open Bookmarks; app.addMenuItem( { cName: "OpenBookmarks", cUser: "Open All Bookmarks", cParent: "View", cExec: "OpenBookmark(this.bookmarkRoot);", cEnable: "event.rc = (event.target != null);" }); // the bookmark open property is not supported by Reader; // Close Bookmarks; app.addMenuItem( { cName: "CloseBookmarks", cUser: "Close All Bookmarks", cParent: "View", cExec: "OpenBookmark(this.bookmarkRoot, 'Close');", cEnable: "event.rc = (event.target != null);" }); } // end viewer type not reader; // tool bar buttons; if(app.viewerType != "Reader") { // removeToolButton try{ app.removeToolButton({cName:"BookmarkOpen"}); } catch (e) { // do nothing; } // add a toolbutton app.addToolButton({ cName: "BookMarkOpen", cExec: "OpenBookmark(this.bookmarkRoot, 'open');", cEnable: "event.rc = (event.target != null);", cTooltext: "Open All Bookmarks" }); try{ app.removeToolButton({cName:"BookmarkClose"}); } catch (e) { // do nothing; } // add a toolbutton app.addToolButton({ cName: "BookMarkClose", cExec: "OpenBookmark(this.bookmarkRoot, 'Close');", cEnable: "event.rc = (event.target != null);", cTooltext: "Close All Bookmarks" }); } // end not reader function ToggleBookmarks() { /* toggle bookmark navigation pane value; Uses the undocumented doc property of pane "" = none "B" = bookmarks "L" = layers "T" = thumbnails author: George Kaiser */ this.pane.toUpperCase() != "B"? this.pane = "B" : this.pane = ""; return true }; // add menu item app.addMenuItem({ cName: "ToogleBookMarks", cUser: "Toggle Bookmarks Pane", cParent: "View", cExec: "ToggleBookmarks();", cEnable: "event.rc = (event.target != null);" }); try{ app.removeToolButton({cName:"ToggleBookmark"}); } catch (e) { // do nothing; } // add a toolbutton app.addToolButton({ cName: "ToggleBookmark", cExec: "ToggleBookmarks();", cEnable: "event.rc = (event.target != null);", cTooltext: "Toggle Bookmarks" });

Updated to either open or close the bookmarks base on passed parameters.


George Kaiser   


Please specify a reason: