How can I access/find named destinations in PDF?

Q:

I need to know how to get a Destination given a PDF and a Destination
Name. Then once I have the destination I can use the
dest.GetPage().GetPageIndex() code, but I am still at the point of
getting the destination. I tried using bookmarks to get the
destination
Bookmark item = m_pdfdoc.GetFirstBookmark().Find(i.Key().GetStr());
if (item.IsValid())

This code gave me bookmarks but not destinations. Is there a way to
get the destination on a PDF that do not have an associated bookmark?

How can I access/find named destinations in PDF?
----

A:

You can access named destinations directly as follows:

Using C++:

init pdfnet
...
PDFDoc doc("mypdf.pdf");
doc.InitSecurityHandler();
NameTree dests = NameTree::Find(doc, "Dests");
if (!dests.IsValid()) return;

// Traversing all destinations in Dests NameTree
NameTreeIterator end = dests.End();
NameTreeIterator i = dests.Begin();
for (; i!=end; ++i) {
  cout << "Key: " << i->Key()->GetStr() << endl;
}

// Searching the NameTree
i = dests.Find("MyDest", 6);
cout << "Key: " << i->Key()->GetStr() << endl;
cout << "Value: " << i->Value()->GetType() << endl;
...

Using C#:

init pdfnet
...
PDFDoc doc = new PDFDoc("mypdf.pdf");
doc.InitSecurityHandler();
NameTree dests = SDF.NameTree.Find(doc, "Dests");
if (!dests.IsValid()) return;

// Traversing all destinations in Dests NameTree
SDF.NameTreeIterator end = dests.End();
SDF.NameTreeIterator i = dests.Begin();
for (; i!=end; ++i) {
  // i.Key().GetStr()
}

// Searching the NameTree
i = dests.Find("MyDest", 6);
// Key: i.Key().GetStr()
// Value: i.Value()
...

Q:

How do I go from the NameTreeIterator to the Destination?

That is, how can do something similar to this?
Destination destiny = "GetMeTheDestinationFunction"(NameTreeIterator
i);
---

A:

NameTreeIterator is a simply a key value pair. To access the key you
would use itr.Key() and to access the value (which is the destination
low-level object) you would use itr.Value().

A high-level PDF:: Destination object can be initialized as follows:

C#
Destination dest = new Destination(itr.Value());

VB.NET
Dim dest as Destination = new Destination(itr.Value())

C++ (Unmanaged / Managed)
Destination dest(itr->Value());

Q:

Thanks again!!
I can now get the destination and then Type and Page of the
Destination..... but (there always is a but.. ) Is there now a why to
get the Double Top, Bottom, Right, and Left of the Destination? This
is needed so that the destination can be recreated on another PDF.
----

A:
You can use SDF/Cos API in PDFNet SDF to query all entries from the
destination array.

For example:

Destination dest = new Destination(itr.Value());
...
// Extract other info from the low level destination...
Obj dest_arr = itr.Value();
string fit_type = dest_arr.GetAt(1).GetName();
if (fit_type == "FitH") {
   // dest_arr.Size() should return 3.
   // Now get the vertical coordinate 'top'
   double top = dest_arr.GetAt(2).GetNumber();
   ...
}
else {
   // See section 8.2.1 'Destinations' in PDF Reference
   // for other destination 'fit' types.
}