How do I create a link to an external PDF document?

Q: Is it possible to add link to a PDF document to navigate to a
location of a page of second PDF document using PDFNet?

Example: first.pdf has a link-second.pdf#location. I would like to
create several PDF documents that will reference to special locations
of pages to each other.
--------

A: You would need to create a 'remote goto action' (i.e. GoToR
action).

The following sample shows how to create a GoToR action & link.

// Create 'relative' FileSpec 'by hand'.
Obj file_spec = doc.CreateIndirectDict();
file_spec.PutName("Type", "Filespec");
file_spec.PutString("F", "dest.pdf");
FileSpec spec = new FileSpec(file_spec);

// The second parameter is the page number... (so, jump to page #5)
Action goto_remote = Action.CreateGotoRemote(spec, 5, true);

Annot link = Annot.CreateLink(doc.GetSDFDoc(), new Rect(85, 458, 503,
502), goto_remote);
page.AnnotPushBack(link);

In case you would like to create a 'Remote GoTo' action (i.e. GoToR
action) to a 'named' destination object in an external PDF document,
you could use the following snippet:

Action goto_remote = Action.CreateGotoRemote (spec, 0, true);

// Set the destination to be the key of the
// named destination in the remote PDF.
goto_remote.PutString("D", "MyDest");

Annot link = Annot.CreateLink(doc.GetSDFDoc(), new Rect(85, 458, 503,
502), goto_remote);
page.AnnotPushBack(link);

This code assumes that the remote document contains the named
destination called "MyDest".

-------
In case you need to create hyperlinks or intra-document links, please
take a look at Annotation sample project (http://www.pdftron.com/net/
samplecode.html#Annotation)

Action goto_remote = Action.CreateGotoRemote (spec, 0, true);

// Set the destination to be the key of the
// named destination in the remote PDF.
goto_remote.PutString("D", "MyDest");

There was an error in the above code snippet. The last line should
read:

goto_remote.GetSDFObj().PutString("D", "MyDest");

Q: I run the example code and it works fine; the example shows how to
Set the destination to be the key of the named destination in the
remote PDF part works but I am still not sure how to create a location
(a named destination such as '#destination') in document so I can
link back to the named destination created by me. Could you give me an
advice on how to create a location with name (#destination) so I can
link to it using URL like document.pdf#destination?
----
A: You can create a named destination (in the remote PDF) as follows:

// In C#
NameTree dests = pdftron.SDF.NameTree.Create(remote_doc, "Dests");
Destination dest = Destination.CreateFit(remote_dest_page);
dests.Put("MyDest ", dest.GetSDFObj());

or in case you are a C++ developer ...

NameTree dests = pdftron::SDF::NameTree::Create(remote_doc, "Dests");
const char* key = " MyDest ";
Destination dest = Destination::CreateFit(remote_dest_page);
dests.Put((UChar*)key, strlen(key), dest.GetSDFObj());

Q: The code used to create a named destination in a remote PDF (see
above) returns the following syntax error:

The best overloaded method match for 'pdftron.SDF.NameTree.Put(byte[],
pdftron.SDF.Obj)' has some invalid arguments.
-----
A: You are right, NameTree.Put() accepts a byte arrays instead of a
string as a first parameter. You can convert a string to a byte array
using .NET utility methods. For example:

NameTree dests = NameTree.Create(remote_doc, "Dests");
Destination dest = Destination.CreateFit(remote_dest_page);
dests.Put(System.Text.Encoding.UTF8.GetBytes("MyDest"),
dest.GetSDFObj());