Add a link to PDF with an external destination

This code sample helps adding an external link to your PDF.

If your PDF refers to a webpage, or to another external document it is important to be able to add an external links to your PDF. This article shows how you can add a link with an external destination; this can be any document or an URL.

using ( FileStream fileIn = new FileStream("SellingYourHome.pdf", FileMode.Open, FileAccess.Read ) )
{
    Document document = new Document( fileIn );

    RemoteDestination destination = new RemoteDestination();
    destination.Path = "PackingLightBrochure.pdf";
    destination.PageIndex = 2; // third page
    destination.PageDisplay = PageDisplay.FitEntire;
    destination.WindowBehavior = WindowBehavior.NewWindow;
            
    GoToAction action = new GoToAction( destination );
    Link link = new Link( 100, 100, 300, 200 );
    link.BorderStyle = BorderStyle.Solid;
    link.BorderWidth = 1;
    link.BorderColor = RgbColor.Red;
    link.MouseUpActions.Add( action );
    document.Pages[0].Links.Add( link );

    using ( FileStream fileOut = new FileStream("remotedestination.pdf", FileMode.Create, FileAccess.Write ) )
    {
        document.Write( fileOut );
    }
}
Using fileIn As New FileStream("SellingYourHome.pdf", FileMode.Open, FileAccess.Read)
	
    Dim document As New Document(fileIn)
    Dim destination As New RemoteDestination()
    destination.Path = "PackingLightBrochure.pdf"
    destination.PageIndex = 2
	
    ' third page
    destination.PageDisplay = PageDisplay.FitEntire
    destination.WindowBehavior = WindowBehavior.NewWindow

    Dim action As New GoToAction(destination)
    Dim link As New Link(100, 100, 300, 200)
    link.BorderStyle = BorderStyle.Solid
    link.BorderWidth = 1
    link.BorderColor = RgbColor.Red
    link.MouseUpActions.Add(action)
    document.Pages(0).Links.Add(link)

    Using fileOut As New FileStream("remotedestination.pdf", FileMode.Create, FileAccess.Write)
        document.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