Q: How do I obtain remote file destinations from a link annotation or
from a bookmark item?
---
A:
You can obtain remote destinations (that are referenced from link
annotations) as follows:
// C# pseudocode
int num_annots = page.GetNumAnnots();
for (int i=0; i<num_annots; ++i) {
Annot annot = page.GetAnnot(i);
if (annot.GetType() == Annot.Type.e_Link) {
Action action = annot.GetLinkAction();
if (action.GetType() == Action::e_GoTo) {
int page_num = action.GetDest().GetPage().GetIndex();
}
else if (action.GetType() == Action::e_GoToR) {
// A remote/external goto action...
Destination dest = action.GetDest();
// Get the file specification dict
Obj file_dict = action.GetSDFObj().Get("F").Value();
FileSpec file_spec = new FileSpec(file_dict);
String file_path = file_spec.GetFilePath();
}
}
The similar logic applies to remote destinations referenced from
bookmark item actions:
If the bookmark action type is 'Action.e_GoToR' (i.e. remote PDF
bookmark) you could obtain the path to referenced external file as
follows:
// C# pseudocode
Action action = bookmark.GetAction();
if (action.IsValid() && action.GetType() == Action::e_GoToR)
{
Destination dest = action.GetDest();
// Get the file specification dict
Obj file_dict = action.GetSDFObj().Get("F").Value();
FileSpec file_spec = new FileSpec(file_dict);
String file_path = file_spec.GetFilePath();
...
}