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

Get Bookmark Title and Page Number Linked To

art_pdf
Registered: Nov 1 2007
Posts: 4

Hello everybody!
I have the PDF document with bookmarks, those also have child bookmarks.
I need to get the titles of the all bookmarks (parent and child) and also get the page numbers they linked to.
I need to do it by VB6.
I guess that I can use the "Javascript" objects - get bookmarks array by objectJS.bookmarkRoot.Children, then get the name of the each bookmark by "Name" property.
But I have two problems:
1. I need to check if the bookmark has children, I use the following code:
objectBookmarks = objectJS.bookmarkRoot.Children
objectBookmarksChildren = objectBookmarks(Index).Children
If first level bookmark has children there are no problem, but if hasn’t I get the error instead on NULL value (as it is described in the reference guide).
What is the problem? May be I can use another functionality to check children existence?
 
2. Also I didn’t find the method or property to get the page number that bookmark linked to.
 
Thanks a lot in advance!!!

My Product Information:
Acrobat Standard 7.0.5, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Because of differences in data types between VB and JS it's difficult to write a lot of code using the JSO object directly. In fact, this is the problem you're seeing. the "bookmarkRoot.children" property returns an array containing a hierachal list of objects. VB can't handle this conversion.

To get around the problem write all of the JavaScript part of your code into a fucntion in a Folder Level Script, i.e. the code for collecting all the bookmark info. Then call this function from the JSO in the VB program. The function should return a string or array that can then be easily parsed on the VB side. I prefer XML since both VB.NET and JS have built-in XML parsers. This method is also more efficient since it separtes the JavaScript only part into it's native environment.

The answer to your second question is that a bookmarks destination is not directly available. However, the easiest way to find out where a bookmark leads is to follow it, use the "bookmark.execute()" fucnction.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

art_pdf
Registered: Nov 1 2007
Posts: 4
Thanks a lot. I appreciate your help.

I used the following way:

oAcrobatApp = CREATEOBJECT("AcroExch.App")
oAcrobatDoc = CREATEOBJECT("AcroExch.PDDoc")

oAcrobatDoc.Open(cPdfFilePath)
oJSO = oAcrobatDoc.GetJSObject

oAcrobatAVDoc = oAcrobatDoc.OpenAVDoc(cPdfFilePath)
oAcrobatDocPage = oAcrobatAVDoc.GetAVPageView()

oAcrobatDocBookmarks = oJSO.bookmarkRoot.Children

‘ Then in the cycle
oAcrobatDocBookmarks(Index).Execute()
oAcrobatDocBookmarks(Index).Name
oAcrobatDocPage.GetPageNum

All the best,
Artyom