Display the name of a PDF bookmark in the header of the bookmarked page

Posted on 2010-01-08
Last Modified: 2012-05-08

I'll make this hypithtical because the actual situation is more complicated.   I have a PDF that has bookmarks referencing different pages in the document.  What I would like to do is have the bookmark's name posted at the top of the bookmarked page.

That's it in a nutshell I use Acrobat Professional so I would like to write a javascript to create the text at the top of each page with a bookmark with the bookmark's name.

The reason is these files are being split apart by bookmark and I would like to display the bookmarks name on the new files first page. its not for formal usage so it doesn't really matter where or how the text with the bookmarks name appears.

Hopefully this is easier than it sounds. Thanks for the tips.

Question by:joshcallahan1
    LVL 44

    Expert Comment

    by:Karl Heinz Kremer
    The problem is that a bookmark is not necessarily a link to a page, a bookmark can for example also open a web page. A bookmark is also not a property of the target page - the bookmark tree is independent of the page tree. When you traverse the bookmark tree in JavaScript, you can get the name of a bookmark, but you cannot get it's "action", so you don't know what it does when executed (but, you can execute it).

    This means that with just JavaScript, your idea will not work. You could write an Acrobat plug-in to analyze the bookmark actions (or do that with the free iText library), but that would be a lot more complicated than to just add a few lines of JavaScript to your document.

    If you want to go the plug-in route, it's beyond the scope of an EE question. I can give you some pointers, but you would have to do a lot of homework to get familiar with the 'guts' of a PDF file first.

    Author Comment


    Before I Accept your answer I have one more scenario to ask you about.  These bookmarks I'm referring to are created when a bunch of small PDF files are combined into one large PDF.  

    In Acrobat when you combine PDF files into one PDF it automatically creates a bookmark named after each PDF file.  Is there any way to add the name of a PDF file to the first page of the file before the files are combined?  I could just run a batch involving the name of the file before hand and then combine them.

    This may need to be opened under another question but I figured you may know. Thanks,

    LVL 44

    Expert Comment

    by:Karl Heinz Kremer
    Yes, that would work. You would add a form field, and then fill that form field with the filename. How familiar are you with Acrobat's JavaScript?

    Author Comment

    I'm a VBA man I have not written much javascript, if you could give me a nudge in the right direction I would appreciate it. Thanks,

    LVL 44

    Accepted Solution

    Sorry for the delay.

    Create a new batch sequence and select to run a JavaScript as part of the sequence, using the following code. You should be able to adjust the code to meet your needs by changing the location and size of the field. You can find more information about the Acrobat JavaScript implementation here:

    var inch = 72;
    // Position a rectangle 
    var aRect = this.getPageBox( {nPage: 0} );
    aRect[0] += .5*inch;            // from upper left hand corner of page.
    aRect[2] = aRect[0]+2*inch;    // Make it 2 inch wide
    aRect[1] -= .5*inch;
    aRect[3] = aRect[1] - 24;       // and 24 points high
    // Now construct a button field with a right arrow from ZapfDingbats
    var f = this.addField("FileName", "text", 0, aRect )
    f.value = this.documentFileName;

    Open in new window


    Author Closing Comment

    Code worded great!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe A recent question here at Experts Exchange piqued my interest, so I decided to provide a thorough solution and publ…
    Have you ever come up with a need of emailing only few pages of PDF file to one of yourfriend or colleague, instead of whole Adobe file? If yes, then surely you have face problems in doing that! Read this section as I have suggested multiple solutio…
    In this third video of the Xpdf series, we discuss and demonstrate the PDFtoText utility, which converts PDF files into plain text files. Download and install the software.: You may have already downloaded and installed the Xpdf tools while watching…
    We often encounter PDF files that are pure images, that is, they do not have text characters, but instead contain only raster graphics. The most common causes of this are document scanning software and faxing software/services that create image-only…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now