PDF Bookmarks as a PopUp Menu

I recently completed a job for one of my customers and in the process developed a little proof-of-concept piece that we ended up not using. The customer wanted a way to navigate a collection of PDF files via bookmarks but didn’t want to lose all of the screen real estate that the bookmark panel takes up. By the time we were done, we ended up using a Flash widget created in Flash Builder rather than a popup menu created in Acrobat JavaScript because they wanted something a little more fancy than what Acrobat could do by itself.

So, lucky you, I’m sharing the original proof-of-concept. In the example file that you can download from the link below, you can click on the “Table of Contents” button and the bookmark list will be presented as a popup menu. This can be a great way of saving precious screen real estate. If you want to use the button in your files, just download and copy it out of the example file and paste it into your document. The JavaScript behind the functionality is below.

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;

function bookmarksAsPopUp(bookmarks)
   if(bookmarks && bookmarks.children)
     for(var i=0;i 0)
			bookmarkName = bookmarkName.substring(0,bookmarkName.indexOf(String.fromCharCode(11))) +" "+ bookmarkName.substring(bookmarkName.indexOf(String.fromCharCode(11))+1)
		popUp = popUp+"{cName: '"+bookmarkName+"', cReturn: '"+bookmarkName+"'" ;
          popUp = popUp + ", oSubMenu: [";
		  popUp = popUp + "]";
		popUp = popUp+"}";
		if (i != bookmarks.children.length-1)
			popUp = popUp+", "
   return popUp;

var popUp = "";
var cChoice = eval("app.popUpMenuEx(" + popUp + ")" ) ;
bkm = searchBookmarks(this.bookmarkRoot, 0, cChoice );
if ( bkm != null ) bkm.execute();

Bookmark PopUp Example Screen Shot

In future versions, you’ll be able to reference bookmarks in another PDF file as well.

Download the Bookmark PopUp Example file (.pdf) [6.7 MB]

6 Responses to PDF Bookmarks as a PopUp Menu

  1. Jean-Renaud Boulay May 28, 2012 at 11:10 am #

    Great, great, great!
    Thank you for sharing that piece of code.

  2. Rick Santos May 28, 2012 at 6:09 pm #

    Very nice Joel!

  3. thomp2 June 14, 2012 at 5:32 pm #

    Hey Joel, I did this years ago and have several variations at http://www.pdfscripting.com/public/department43.cfm

  4. XavierHU March 4, 2013 at 5:08 am #

    The button is not working on ipad.

    • Joel_Geraci March 4, 2013 at 5:49 pm #

      Unfortunately, you are correct. It doesn’t. The Adobe Reader on iPad does not allow JavaScripts in the PDF to run.

  5. Shlomo Perets April 9, 2013 at 6:52 am #

    Nice! Thank you, Joel!

    Bookmark hierarchy poses a problem, however. Whereas in the Bookmarks panel, a higher-level bookmark can both serve as a heading for lower-level entries as well as link to a location, in the pop-ups such a bookmark becomes a menu heading only.

Leave a Reply

Powered by WordPress. Designed by Woo Themes