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:

In PDF format, hyperlinks are represented as a special type of
annotations. You can create a new link annotation as follows (assuming

// 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),

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

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

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

  Element element;
  if (draw_background) {
    element = builder.CreateRect(pos.x1, pos.y1, pos.Width(),

    element.GetGState().SetFillColor(new ColorPt(0.75));

  // Draw Link text

  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,
  else {
    element.SetTextMatrix(1, 0, 0, 1, pos.x1, pos.y1);


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

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

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