Q: How do I add a text-link or a hyperlink to pdf documents?
------
A: As a starting point you may want to take a look at Annotation
sample project:
http://www.pdftron.com/net/samplecode.html#Annotation
In PDF format, hyperlinks are represented as a special type of
annotations. You can create a new link annotation as follows (assuming
C#):
// Create a 'goto' link to page #3 in the same document...
Action link_action =
Action.CreateGoto(Destination.CreateFitH(doc.GetPage(3), 0)); Annot
link = Annot.CreateLink(doc.GetSDFDoc(), new Rect(85, 458, 503, 502),
link_action);
page.AnnotPushBack(link);
The first parameter is the document where the link should be created,
the second parameter is the link region (in PDF user coordinate
system), and the last parameter is the link action. The last line add
the annotation to a given page.
The above code shows how to create an 'intra-document' link. To create
a hyperlink that can open a URL in the default web browser use the
following code snippet:
// Create a hyperlink...
Annot hyperlink = Annot.CreateLink(doc, new Rect(85, 570, 503, 524),
Action.CreateURI(doc, "http://www.pdftron.com"));
page.AnnotPushBack(hyperlink);
Please note that Action.CreateURI() utility method is available
starting with PDFNet v.4.0.4. You can implement the same functionality
using an older version of PDFNet as follows:
// Create a hyperlink using the old API
Obj action = doc.CreateIndirectDict();
action.PutName("S", "URI");
action.PutString("URI", "http://www.pdftron.com");
Annot link = Annot.CreateLink(doc, new Rect(85, 458, 503, 502), new
Action(action)); page.AnnotPushBack(link);