Skip to main content Skip to footer

How to Create a Link to a Destination Within a Document

It is possible to create "anchor-like" links programmatically to link between different locations within your document.This can be achieved using Annotations, and we can also use Outlines to create a list of the annotations.

For example, this snippet will look for an instance of a string and link to a target string. "Link" will search for the intended string, and "Target" will search for the string you want to link to:

if (link != null && target != null)
{
    var rcTarget= target.Bounds[0].ToRect();
    var rcLink = link.Bounds[0].ToRect();
    OutlineNode on2 = new OutlineNode(_link, new DestinationXYZ(target.PageIndex, rcTarget.X, pdf.PageSize.Height- rcTarget.Y, 1));    
    pdf.Pages[link.PageIndex].Annotations.Add(new LinkAnnotation(rcLink,on2.Dest));    
    pdf.Outlines.Add(on2);
}

Tags:

Tye Glenz