How to get a page number from e_gotoR action (a remote goto link)?

98 views
Skip to first unread message

Support

unread,
Mar 23, 2007, 8:03:21 PM3/23/07
to PDFTron PDFNet SDK
Q:
We need to get the page number for a
So far we can get only the destination filename. We now need to obtain
the destination page for e_gotoR.

---
A:

You may want to search for "How to find the page number the
destination points to in the remote PDF document?" in PDFTron PDFNet
SDK forum for more information on this topic.

Please keep in mind that the remote destination page number is not
always available in the source document.

In PDF document the remote destination may be a name which is a named
destination in the remote document (the advantage of this approach is
that the user could insert and delete pages in the remote document
without invalidating GoToR links). In this case you need to:
a) open the remote document
b) lookup the name destination in the remote document. This will give
you the page (and page number in the remote document).

If you look at the code in the referenced article you will find out
how to obtain the page number in the remote document...

int page_num;
....
// Get the remote destination.
Obj dest = action_dict.Get("D").Value();
if (dest.IsString()) {
// Find named destination in the remote document
// Format used in PDF 1.2 and above
... Open the remote_doc ...
Obj name_tree_root =
remote_doc.GetRoot().Get("Names").Value().Get("Dests").Value();
NameTree nt = new NameTree(name_tree_root);
NameTreeIterator itr = nt.Find(dest.GetBuffer(), dest.Size());
if (itr != nt.End() {
Destination remote_dest = new Destination(itr.Value());
page_num = remote_dest.GetPage().GetIndex();
...
}
}
else if (dest.IsName()) {
// Find named destination in the remote document
// PDF 1.1 format which is obsolete these days.
... Open the remote_doc ...
Obj rdest =
remote_doc.GetRoot().Get("Dests").Value().Get(dest.GetName()).Value();
Destination remote_dest = new Destination(rdest);
page_num = remote_dest.GetPage().GetIndex();
}
else {
// In this case 'dest' is an array defining an
// explicit destination. Its first element must be a page
// number within the remote document rather. The first
// page is numbered 0.
page_num = (int) dest->GetAt(0)->GetNumber();
}

Jose Capelan

unread,
Jul 17, 2016, 2:36:34 AM7/17/16
to PDFTron PDFNet SDK
Can some one translate this for php sdk?
I can't find any doc on how to extract the page in php (or named destination)

thanks!

Ryan

unread,
Jul 18, 2016, 4:53:55 PM7/18/16
to PDFTron PDFNet SDK
We provide all our sample code in all available languages, including PHP.

For example, the Bookmark sample code is a good comparison.

But here is an untested translation

$page_num = 0;
$dest = $action_dict.Get("D").Value();
if ($dest.IsString()) {
  ... Open the remote_doc ...
  $name_tree_root = $remote_doc.GetRoot().Get("Names").Value().Get("Dests").Value();
  $nt = new NameTree($name_tree_root);
  $itr = $nt.Find($dest.GetBuffer(), $dest.Size());
  if ($itr != $nt.End() {
    $remote_dest = new Destination($itr.Value());
    $page_num = $remote_dest.GetPage().GetIndex();
    ...
   }
}
else if ($dest.IsName()) {
  ... Open the remote_doc ...
  $rdest = $remote_doc.GetRoot().Get("Dests").Value().Get($dest.GetName()).Value();
  $remote_dest = new Destination($rdest);
  $page_num = $remote_dest.GetPage().GetIndex();
}
else {
  // In this case 'dest' is an array defining an
  // explicit destination. Its first element must be a page
  // number within the remote document rather. The first
  // page is numbered 0.
  $page_num = (int) $dest->GetAt(0)->GetNumber();



Reply all
Reply to author
Forward
0 new messages