22 Replies Latest reply on Aug 10, 2016 8:58 AM by JoeKincognito

    Expand/Collapse all the Bookmarks in a PDF file

    Antonella11 Level 1

      Hi,

       

      This is my first message on the board :-)

       

      I work with very large PDF files (i.e 2000 pages, 700 bookmarks on 5 or 6 levels!) and I'm looking for a script (Acrobat 9 Pro) allowing to expand/collapse all the bookmarks in a PDF file.

       

      Thanks in advance for your valuable help,

      Cheers

       

      Antonella

        • 1. Re: Expand/Collapse all the Bookmarks in a PDF file
          WA3CAS Level 1

          Antonella,

           

          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.

           

          JBrush

          • 2. Re: Expand/Collapse all the Bookmarks in a PDF file
            try67 MVP & Adobe Community Professional

            It's possible to collapse/expand all bookmarks in a file with a script.

             

            PS - this message is from January... I think the OP probably solved it by

            now.

            • 3. Re: Expand/Collapse all the Bookmarks in a PDF file
              WA3CAS Level 1

              Just trying to help. So where can I get a copy of this script?

              • 4. Re: Expand/Collapse all the Bookmarks in a PDF file
                Plstsn Level 3

                The Acrobat Javascript Scripting reference (http://partners.adobe.com/public/developer/en/acrobat/sdk/AcroJS.pdf) describes how to use scripting to access bookmarks and how to open and close them, which is what you're looking for.

                 

                I suggest you read the reference and make a function that will do the job for you.

                 

                That's the way I would do it.

                 

                I don't think you can access the keyboard shortcuts "/" and "Shift + *" via scripting.

                 

                Torben.

                1 person found this helpful
                • 5. Re: Expand/Collapse all the Bookmarks in a PDF file
                  tsurikov Level 1

                  The following works to collapse all bookmarks at all levels in Acrobat 9 Pro:

                   

                  • Click on any bookmark in the navigation pane.
                  • Press Shift + (the forward-slash key on the numeric keypad).

                   

                  The numeric-keypad part is significant; using the regular forward-slash key doesn't work.

                  2 people found this helpful
                  • 6. Re: Expand/Collapse all the Bookmarks in a PDF file
                    ashish gupta. Adobe Employee

                    Old thread, but adding my reply here. Apparently this thread is pretty high up in Google searches for PDF bookmarks!

                     

                    For future visitors, I am leaving a useful tip I blogged at http://twtools.wordpress.com/2011/09/26/expand-or-collapse-pdf-bookmarks-and-save-that-sta te/.

                    • 7. Re: Expand/Collapse all the Bookmarks in a PDF file
                      rlauriston Level 1

                      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.

                      • 8. Re: Expand/Collapse all the Bookmarks in a PDF file
                        rlauriston Level 1

                        Anybody know how to do this on a Mac laptop?

                         

                        The only way I've managed to do it is by attaching an external keyboard to my Windows laptop.

                         

                        Given that this is a basic requirement for professional-quality PDFs, well, actually, no surprise that Adobe doesn't make it easy.

                        • 9. Re: Expand/Collapse all the Bookmarks in a PDF file
                          gkaiseril MVP & Adobe Community Professional

                          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.

                          // example of usage
                          OpenBookMark(this.BookmardRoot, true);

                          This function is recursively calls itself to work through the bookmark tree.
                          */
                          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
                          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"
                            });
                           

                           

                          I'll let you figure out how to add the menu item or toolbar button.

                          • 10. Re: Expand/Collapse all the Bookmarks in a PDF file
                            Karl Heinz Kremer Adobe Community Professional

                            Shift-Ctrl-Option-/ But, this only works in Acrobat 9, Acrobat X, XI and DC do not seem to have a way to do this. Acrobat 9 is not supported on any recent version of Mac OS X.

                            1 person found this helpful
                            • 11. Re: Expand/Collapse all the Bookmarks in a PDF file
                              gkaiseril MVP & Adobe Community Professional

                              For Acrobat/Reader DC the help file shows:

                               

                              Expand the current bookmark (focus on Bookmarks panel)

                              Right Arrow or Shift+plus sign

                              Right Arrow or Shift+plus sign

                              Collapse the current bookmark (focus on Bookmarks panel)

                              Left Arrow or minus sign

                              Left Arrow or minus sign

                              Expand all bookmarks

                              Shift+*

                              Shift+*

                              Collapse selected bookmark

                              Forward Slash

                              Forward Slash

                               

                              Center column is for Windows, right column for Mac.

                               

                              Acrobat Help Shortcuts for the full list. They appear to change with the version.

                              • 12. Re: Expand/Collapse all the Bookmarks in a PDF file
                                rlauriston Level 1

                                Right, but I'm looking for the command to collapse all bookmarks.

                                • 13. Re: Expand/Collapse all the Bookmarks in a PDF file
                                  gkaiseril MVP & Adobe Community Professional

                                  I have poste the JavaScript to open/close all the bookmarks as well as the keyboard short cuts. There no single JavaScript command provided by Adobe. The code I provided can open/close all bookmarks

                                   

                                  I provided a the single JavaScript command that can open all the bookmarks once the code has been properly installed in the application folder or the PDF.

                                   

                                  The following JavaScript command will close all bookmarks:

                                   

                                  OpenBookMark(this.BookmardRoot, false);

                                   

                                  With some additional coding you can add this to Acrobat as menu item or a toolbar button and that button can be added to the quick bar.

                                   

                                  You will still have to install the provided script.

                                  • 14. Re: Expand/Collapse all the Bookmarks in a PDF file
                                    aimless9 Level 1

                                    This worked for me, at the ROOT bookmark.  I did not need to select each top level.  Thank you so much for posting - I read the keyboard shortcuts before and assumed it meant the same as others do. 

                                    Thank you!!!

                                    • 15. Re: Expand/Collapse all the Bookmarks in a PDF file
                                      rlauriston Level 1

                                      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.

                                      1 person found this helpful
                                      • 16. Re: Expand/Collapse all the Bookmarks in a PDF file
                                        rlauriston Level 1

                                        "I did not need to select each top level."

                                         

                                        If you have a root bookmark, that is the only top-level bookmark.

                                        • 17. Re: Expand/Collapse all the Bookmarks in a PDF file
                                          gkaiseril MVP & Adobe Community Professional

                                          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.

                                          • 18. Re: Expand/Collapse all the Bookmarks in a PDF file
                                            rlauriston Level 1

                                            I know it's a user-to-user forum, but I'm pretty sure Adobe employees monitor it.

                                             

                                            That's great that someone wrote a script, but I want Adobe to fix the UI.

                                            • 20. Re: Expand/Collapse all the Bookmarks in a PDF file
                                              jasons33352889 Level 1

                                              I have Adobe 9, maybe I'm misunderstanding the question, but on the bookmark pane, can't you click the "gears" and click on "expand/collapse top level book marks"?

                                              • 21. Re: Expand/Collapse all the Bookmarks in a PDF file
                                                try67 MVP & Adobe Community Professional

                                                But they want to expand/collapse all bookmarks, not just the top-level ones...

                                                • 22. Re: Expand/Collapse all the Bookmarks in a PDF file
                                                  JoeKincognito Level 1

                                                  With the top level root bookmark highlighted you can use:

                                                  *   to expand all bookmarks (multiple layers deep)

                                                  /   to collapse all bookmarks