That should be easy, just follow the references !
If you open a Pdf with a text-editor, you should be able to see, what i mean.
The outlines are defined in the document catalog: (object numbers will probably differ)
Code:
2 0 obj
<<
/Type/Catalog
/Pages 3 0 R
/Outlines 13 0 R
The "/Outlines" Entry is a reference to the Outlines-Dictionary:
Code:
13 0 obj
<<
/First 14 0 R
/Last 83 0 R
The "/First" entry references the first outline:
Code:
14 0 obj
<<
/Title(Page1)
/Parent 13 0 R
/Dest[4 0 R /XYZ null null 0]
/Next 28 0 R
>>
The "/Title" entry contains the name of the bookmark.
The "/Next" entry contains a reference to the next bookmark.
The "Dest" entry contains an array; the first element is a reference to the page.
Note, that the "/Next" entry will be missing if you reached the last bookmark.
Now, what i would do to find a page by a bookmark's name: (in pseudocode)
Code:
var outlinesDict = Catalog.GetDictionary("/Outlines");
if (outlinesDict != null)
{
var outline = outlinesDict.GetDictionary("/First");
while (outline != null)
{
var title = outline.GetString("/Title");
if (title == "title_i_search_for") // bookmark we're looking for ?
{
var destArray = outline.GetArray("/Dest");
var pageRef = destArray.GetReference(0); // stored at index zero
for (var i = 0; i < document.NumPages; i++)
if (document.Pages[i].ObjectNumber == pageRef.ObjectNumber)
// Page found ! return page or whatever
}
// not the right bookmark, check next one
outline = outline.GetDictionary("/Next");
}
}
You should probably add more error-checking (i.e. check, whether destArray and pageRef are valid).