---
title: "Add a hyperlink to a PDF in C#"
url: https://recursiveai.org/onepdf/cookbook/add-link-to-pdf/
description: "Add a clickable hyperlink to a new PDF in C#. Use OnePDF to place a link annotation over a rectangle and open a web address when the reader clicks it."
version: "1.25.0"
---

# Add a hyperlink to a PDF in C#

**OnePDF** is a free, open-source PDF library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OnePdf) · [GitHub](https://github.com/recursive-ai-oss/onepdf-csharp) · [Docs](https://recursiveai.org/onepdf/docs/) · [Download example (.zip)](https://recursiveai.org/onepdf/cookbook/add-link-to-pdf/add-link-to-pdf.zip)

Make a text label clickable on a new PDF page. In an existing PDF, OnePDF 1.25.0 can add a link by [editing the page’s annotation array](https://recursiveai.org/onepdf/docs/writing/#the-mutable-view), not by calling `AddLink`.

```shell
dotnet add package RecursiveAI.OnePdf
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OnePdf;

using var file = File.Create("link.pdf");
using var writer = new PdfDocumentWriter(file);
var page = writer.BeginPage(200, 120);
var area = new PdfRectangle(19, 57, 116, 73);
page.AddLink(area, "https://example.org/");
var font = writer.AddStandardFont("Helvetica");
page.SetFont(font, 12);
page.SetFillRgb(0, 0, 0.8);
page.DrawText("Visit example.org", 20, 60);
page.Commit();
writer.Finish();
Console.WriteLine("Wrote link.pdf");
```

Unzip [the example](https://recursiveai.org/onepdf/cookbook/add-link-to-pdf/add-link-to-pdf.zip), then `dotnet run`.

Open `link.pdf` and click “Visit example.org” to follow the link.

```text
Wrote link.pdf
```

`AddLink` throws `ArgumentException` if the rectangle is empty or its coordinates aren’t finite.

## Variations

**Jump within the PDF instead of opening a website.** Replace the `AddLink` line with these two lines. This links to the named position `start` on the first page (`pageIndex: 0`); `120` is the destination’s y position in points.

```csharp
writer.AddNamedDestination("start", 0, 120);
page.AddLinkToDestination(area, "start");
```

## Related recipes

- [Create a PDF in C#](https://recursiveai.org/onepdf/cookbook/create-pdf/)
- [Add a QR code to a PDF](https://recursiveai.org/onepdf/cookbook/add-qr-code-to-pdf/)

## The short answer

When creating a PDF in C#, call `page.AddLink(area, "https://example.org/")` on a page opened with `PdfDocumentWriter.BeginPage`. It writes a link annotation with a URI action, which tells the PDF viewer what address to open. Draw the label separately, then commit the page and call `Finish()` to complete the file. You don’t need to show the full URL on the page, and the writer doesn’t fetch it.

## How do I add a clickable hyperlink to a PDF?

Use the same page coordinates for the visual content and the link rectangle. `PdfRectangle` takes **left, bottom, right, top**, not x, y, width, height. These numbers are in PDF points and y increases upward. In the example, the baseline of the label is at `(20, 60)`. The link starts at `(19, 57)` and ends at `(116, 73)`, leaving space below the baseline and above the letters. If you replace the label with a longer one or use a larger font, adjust the right and top edges so the whole label remains clickable.

The rectangle can sit over an image or a shape as well. It doesn’t draw anything: the blue text in the example comes from `SetFillRgb` and `DrawText`. For an internal jump, use the named-destination variation instead. Its target is part of the PDF, so the viewer doesn’t have to open a browser.

## Why won’t my hyperlink work in a PDF?

First check that you’re opening the saved PDF, not a screenshot or a printed copy. If the pointer only reacts beside the label, compare the page coordinates used to draw the label with the bounds passed to `AddLink`. A common mix-up is to give the rectangle a width where it expects a right edge.

If the clickable area is in the right place but the website doesn’t open, check the full address, including `https://`. `AddLink` writes the address into the PDF; it doesn’t check whether the site exists. The viewer decides whether to open external addresses. If it prompts before opening one, that’s separate from the link annotation itself. See the [content creation guide](https://recursiveai.org/onepdf/docs/content-creation/) for the streaming writer’s link and destination APIs.
