Although I don't know of any single command that collapses all bookmarks, I did find a way to collapse all bookmarks under a single top-level bookmark. Highlight the top-level bookmark and press the "/" key. This will collapse all bookmarks multiple layers deep. Repeat for each top-level bookmark. I'm assuming you don't have 700 top-level bookmarks. If you do, this procedure may not help.

Thanks for the tip. Can't figure out how to get it to work on my Mac (I'll borrow a numeric keypad and see if that helps) or with the Fn numeric keys on my Windows laptop, but it works fine with Windows using an external keyboard.

It is possible to collapse a given bookmark with JavaScript or to close all levels of bookmarks by "walking" the bookmark tree from the bottom levels to the top level.

// 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.

Hey, Adobe, it would be nice if you would change the "Collapse all" shortcut or provide a menu command, so I would not have to copy the PDF from my MacBook to my PC laptop and attach a keyboard with a numeric keypad in order to do this one small task.

Hey rlauriston. This is a User 2 User forum not Acrobat or Adobe Help Desk. The posters here are individuals providing free assistance. The posted script was developed by a user and not an Adobe employee. Adobe provides a usable product that can have custom features added by users as needed either by using the simple language JavaScript or creating add-ins using a full computer language like C++.

If you want to add a suggestion or improvement idea you need to do this through the Adobe site under the contact page.

No script needed, click on the top level bookmark and press the / key to collapse all bookmarks. You can then use the right arrow key to expand just the next level of bookmarks. You can then use the left arrow key to collapse that level of bookmarks.

To expand all bookmarks below any given bookmark, press the * key. The / key also works to collapse all bookmarks below any given bookmark.

I wanted to use JavaScript in an Action inside the Action Wizard, Acrobat DC Pro, to collapse all bookmarks in the tree.

I started with a recursive function, similar to the script above, and similar to the example in the JavaScript™ for Acrobat® API Reference.

I then came across a PDF with in excess of 1,500 bookmarks in 5 or 6 layers, and the recursive function crashed Acrobat! I guess this is because the recursive function continually reuses the same variable multiple times, and the JavaScript engine couldn't cope.

The script also sends the name of the bookmark to the console. The console eventually added: "Cannot continue printing to the console." It had captured 1,580 bookmarks at this point.

I used the if () followed by for (), and simply nested this multiple times, and it worked!

You have filled the console display full of messages to the point it can no longer display any message. The JavaScript engine has detected this condition and realizes it cannot print any more messages so it shuts down on this error. Remove the print messages, print fewer messages, or clear the console before every print.

Filling the console with too many messages was not what caused the recursive function to crash. I tried to catch the error, but it crashed anyway.

The long function above works fine, but with 1,580 plus bookmarks, the console filled up. This did not cause the JavaScript engine to crash, it just wrote the polite note: "Cannot continue printing to the console.", and stopped printing to the console. The console had only two other lines before the function started to list all the bookmarks.

I mentioned this to explain why I don't know exactly how many bookmarks there are.

A recursive function is in the bookmark example in the JavaScript™ for Acrobat® API Reference. Folks need to be aware that this could crash if the PDF has a very large nest of bookmarks.

The long way above works, although it does assume there are no more than 8 levels. I suppose it would be possible to introduce a recursive function at level 6, 7 or 8, as it would probably not have much work to do beyond that level. But, it's also quite easy to cut, paste and edit an additional level, if necessary.

I think the use of 'this' to access the PDF is fine for document JavaScripts. However, I don't think it will work with a JavaScript that is part of an Action. The following works with multiple PDFs open at once.

David

// Not entirely sure how to access docs!!try{// Front most seems to be last! d = app.activeDocs[app.activeDocs.length -1] d.info.Title //Find out if d has any properties! Msg ="activeDocs[n]"}catch(e){ d =this Msg ="this"}// Now use d as document object... console.println (Msg)