Add hyperlink to PDF

This code samples draws a hyperlink on an existing PDF page. The link is added as a link annotation. A URI action is associated with the mouse up event.

<![CDATA[using (FileStream fileIn = new FileStream("in.pdf", FileMode.Open, FileAccess.Read))
{
    Document pdf = new Document(fileIn);

    Page page = pdf.Pages[0];

    Link link = new Link();
    page.Links.Add(link);

    // position link at the top-right corner
    link.Height = 40;
    link.Width = 100;
    link.Left = page.Width - link.Width;
    link.Bottom = page.Height - link.Height;

    // add a UriAction to the mouse up event
    link.MouseUpActions.Add(new UriAction("http://www.tallcomponents.com"));

    using (FileStream fileOut = new FileStream("out.pdf", FileMode.Create, FileAccess.Write))
    {
        pdf.Write(fileOut);
    }                
}
Using fileIn As New FileStream("..\..\..\inputDocuments\BlueWater.pdf", FileMode.Open, FileAccess.Read)
    Dim pdf As New Document(fileIn)

    Dim page As Page = pdf.Pages(0)

    Dim link As New Link()
    page.Links.Add(link)

    ' position link at the top-right corner
    link.Height = 40
    link.Width = 100
    link.Left = page.Width - link.Width
    link.Bottom = page.Height - link.Height

    ' add a UriAction to the mouse up event
    link.MouseUpActions.Add(New UriAction("http://www.tallcomponents.com"))

    Using fileOut As New FileStream("..\..\out.pdf", FileMode.Create, FileAccess.Write)
        pdf.Write(fileOut)
    End Using
End Using
Download PDFKit.NET 5.0
We will send you a download link
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download

We have sent an email with a download link. Alternatively, you may want to use the NuGet package manager to install our library.

Nuget ID

Use the NugetID and start right away, or download the package and install it handmatically