Skip to main content
Inspiring
April 3, 2023
Question

SDK C++ finding a specific bookmark I create

  • April 3, 2023
  • 2 replies
  • 745 views

I am adding a bookmark to a legend for some annotation marks used in the document. It works fine for interactive use. But i also need to ba able to find it programmatically, ideally by some other method than looking for text.

The addition is very simple:

 

PDBookmark bmRoot, bmNode;
bmRoot = PDDocGetBookmarkRoot(pdDoc);
bmNode = PDBookmarkAddNewChild(bmRoot, pOptions->LegendTickmarksHeader.c_str());

 

the string being something they can set in options, but it would be optimal if they could edit it. I don't see a way to add anything like a tag that wouldn't be visible but that I could use. 

This topic has been closed for replies.

2 replies

Thom Parker
Inspiring
April 18, 2023

So you want some extra piece of unique data attached to a bookmark, so you can search for it regardless of any external changes made by the user? 

There are a couple of options. 

1) All bookmark entries are indirect COS objects, so they have a unique object ID that can be used to uniquely identify the bookmark.  When the user edits a bookmark, the indirect object remains the same. The object would only be lost if the user deleted the bookmark.  Even resetting the destination and moving the bookmark to a different location in the bookmark tree will not change the object ID.  

2) Add your own key to the bookmark object.  Acrobat ignore entries it doesn't need to muck about with.   So again,  resetting the destination and moving the bookmark do not affect any custom entries in the bookmark object. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Braniac
April 3, 2023

To find a bookmark you need to step through them. The text is available from PDBookmarkGetTitle. This might be in PDFDocEncoding or BOM-prefixed UCS-2 Unicode. 

To step through bookmarks look at PDDocGetBookmarkRoot, PDBookmarkGetNext. Because bookmarks may be nested you need to recursively use PDBookmarkGetFirstChild and enumerate the children.

In theory you could add an extra key to the bookmark ("Outline") dictionary. PDBookmarkGetCosObj gives you the Cos object for adding/checking extra keys. You will need to read about the structure of bookmarks (outlines) in the PDF Reference. 

To allow editing of the extra info you'd need to create your own UI. You cannot add anything to the existing bookmark UI. 

Inspiring
April 4, 2023

I mean that users can edit the bookmark name or delete content that includes the bookmarked content, so searching by the title may not be dependable. In my case, I may just document it. If they change the name and the legend is later updated, it will create a new one instead of updating current.