How do I add a text-link or a hyperlink to pdf documents?

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);

Q: Thank you for your quick and helpful response. You showed me, how
to create a rectangular region inside the document which links to
another destination inside the document.

But I don't want a rectangular region to represent this link, but a
text, so that a click on this text-link will make the reader jump to
the destination.

Of course, I could draw the text separately, calculate the dimension
of the text and create a link region - but as this is quite
uncomfortable I wonder if there was any possibility to automatically
combine this steps.
---
A: Unfortunately PDF format does not support non-rectangular links -
i.e. the hyperlink region can't be associated with a text outline.

In case you would like to add a link along with text (and possibly
image, vecror art) you need to a) stamp the page with new text, b) add
a link for that region.

The following utility method (in C#) illustrates how this can be
implemented. Please note that you have complete freedom to extend or
modify the code to meet your visual and presentation requirements:

Sample use case:

AddTextLink(first_page, "My LINK", "http://www.pdftron.com", new
Rect(85, 570, 503, 524), true, true);

static void AddTextLink(Page page, String link_txt, String uri,
     Rect pos, bool center_align, bool draw_background)
{
  pos.Normalize();

  // 1) Add new page content
  ElementBuilder builder = new ElementBuilder();
  ElementWriter writer = new ElementWriter();
  writer.Begin(page);

  Element element;
  if (draw_background) {
    element = builder.CreateRect(pos.x1, pos.y1, pos.Width(),
pos.Height());
    element.SetPathFill(true);
    element.SetPathStroke(false);

element.GetGState().SetFillColorSpace(ColorSpace.CreateDeviceGray());
    element.GetGState().SetFillColor(new ColorPt(0.75));
    writer.WriteElement(element);
  }

  // Draw Link text
  writer.WriteElement(builder.CreateTextBegin());

  pdftron.SDF.SDFDoc doc = page.GetSDFObj().GetDoc();
  double font_size = 12;
  element = builder.CreateTextRun(link_txt, Font.Create(doc,
Font.StandardType1Font.e_helvetica_bold), font_size);
  element.GetGState().SetFillColor(new ColorPt(0));
  if (center_align) {
    element.SetTextMatrix(1, 0, 0, 1,
        pos.x1+(pos.Width()-element.GetTextLength())/2,
        pos.y1+(pos.Height()-font_size)/2);
    }
  else {
    element.SetTextMatrix(1, 0, 0, 1, pos.x1, pos.y1);
  }

  writer.WriteElement(element);
  writer.WriteElement(builder.CreateTextEnd());
  writer.End();

  // Calling Dispose() on ElementReader/Writer/Builder can result in
  // increased performance and lower memory consumption.
  writer.Dispose();
  builder.Dispose();

  // 2) Create the link annotation
  page.AnnotPushBack(Annot.CreateLink(doc, pos, Action.CreateURI(doc,
uri)));

  // In case you would like to create intra-document links replace the
above line with
  // page.AnnotPushBack(Annot.CreateLink(doc.GetSDFDoc(), pos,
  //
Action.CreateGoto(Destination.CreateFitH(doc.GetPage(page_number),
0)) ));
}