Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically insert bookmark

Status
Not open for further replies.

jiana

Programmer
Jul 2, 2003
5
US
I need to programmatically insert a bookmark into a PDF using Visual Basic. I have access to both Adobe 4 and 5. Any suggestions?
 
You'll quickly find that Acrobat's IAC (COM implementation) provides bare-bones functionality. They do provided a CAcroPDBookmark object, but it doesn't provide a Create() method! You can get and set titles with it, navigate and destroy bookmarks, but as far as I can tell, you can't create them.

However, in Acrobat's JavaScript DOM, there is also a Bookmark Object, which has a CreateChild() method and an InsertChild() method. These appear to let you create bookmarks.

There doesn't appear to be any way for VB to communicate with the JS object though, so passing in names/labels (strings) from VB for a JavaScript function to use might not be possible.

Sorry... but Adobe has historically provided extremely weak Automation/COM support with Acrobat.

So my suggestion is to table VB for now and look into JavaScript.

If you're creating your PDFs from PostScript, you can use the pdfmark operator to build bookmarks and other link annotations.





Thomas D. Greer
 
Thanks a bunch. I finally got tired of searching the web for an answer that doesn't exist. I'll try JavaScript. Thanks again.

Jiana
 
The solution does exist. I am using Adobe Acrobat 4 and Visual Basic 6.

Dim PDBookmark As CAcroPDBookmark
Dim AcroApp As CAcroApp
Dim AVYourDoc As CAcroAVDoc
Dim PDYourDoc As CAcroPDDoc
Dim bFileOpen4 As Boolean
Dim btitle As Boolean


'Create the Acrobat Object
Set acroApp = CreateObject("AcroExch.App", "")
'Show the Application
acroApp.Show
'Create Doc objects
Set PDYourDoc = CreateObject("AcroExch.PDDoc", "")
Set AVYourDoc = CreateObject("AcroExch.AVDoc", "")
'code to load your doc doc
bFileOpen4 = AVYourDoc.Open("path to your doc", "Window Title")
Set PDYourDoc = AVYourDoc.GetPDDoc
'Create BookMark Object
Set PDBookmark = CreateObject("AcroExch.PDBookmark", "")
'activate the app
acroApp.Show
'execute the menu item
acroApp.MenuItemExecute ("NewBookmark")
'set bookmark title
btitle = PDBookmark.GetByTitle(PDYourDoc, "Untitled")
btitle = PDBookmark.SetTitle("bookmarktitle")
 
I've also learned that their is now, in Acrobat 6.0 a JSObject that you can instantiate from VB to get to the JavaScript objects/methods.

The ExecuteMenuItem is a good trick, I've had to fall back on that a lot for methods that the API simply doesn't include.

Thomas D. Greer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top