These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Extracting pages between bookmarks using Javascript

andrewscheinman
Registered: Jan 28 2008
Posts: 3

I routinely need to extract the pages between bookmarks, and wonder how to do this in javascript. I know I can use this.extractpages once I have the nStart and nEnd parameters, but what I don't know is how to find out the page number that a bookmark references, i.e., that you go to when the bookmark is clicked?

Any ideas?

Thanks in advance!

My Product Information:
Acrobat Pro 8.1.1, Macintosh
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Since bookmarks can do more than just go to a page and the adtion of a bookmark is not available to JavaScript, this is not possible.

George Kaiser

andrewscheinman
Registered: Jan 28 2008
Posts: 3
Actually, your information was very helpful to me but incorrect.

After reading what you wrote I spent more time digging through the Adobe javascript manual for acrobat, and found that you can execute a bookmark using

thisbookmarkRoot.chilren[x].execute()

where x is the particular child bookmark you want. For a bookmark that, when clicked, goes to a particular page, this construct will do exactly that, take you to a particular page.

From there it's just a matter of getting the page number using something like

var thecurrentpage = this.pageNum;

So if you have a .pdf with bookmarks that mark off a particular section you want to extract, you'd .execute each of them, set a variable to the page you go to (note that you may have to add a 1 to the page since pages start at 0), and then you could do, in my case, an extract ...

Never say never.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You are right, but in general one can not directly access the code associated with a bookmark. Not all bookmarks go to pages, for example you can add any number of actions to a bookmark. So your method will work if and only if the bookmark has a goto page action or a go to destination. It will not work if a new pdf is opened, an alert is popud up, the PDF is switched to full screen, etc.

George Kaiser