ComponentOne PDF for .NET
Adding Links to a PDF Document
Using ComponentOne PDF for .NET > Adding Bookmarks and Annotations > Adding Links to a PDF Document

The PDF specification allows you to add several types of annotations to your documents. Annotations are often added by hand, as highlights and notes. But they can also be added programmatically. C1PdfDocument provides methods for adding hyperlinks, hyperlink targets, and file attachments to your PDF documents.

To add a hyperlink to your document, use the AddLink method. AddLink method takes two parameters: a string that specifies a url and a RectangleF that specifies the area on the current page that should behave as a link.

Note that the AddLink method does not add any visible content to the page, so you will usually need another command along with AddLink to specify some text or an image that the user can see. For example, the code below adds a string that says "Visit ComponentOne" and a link that takes the user to the ComponentOne home page:

Dim rect As New RectangleF(50, 50, 100, 15)
Dim font As New Font("Arial", 10, FontStyle.Underline)
_c1pdf.AddLink("https://www.grapecity.com/", rect)
_c1pdf.DrawString("Visit ComponentOne", font, Brushes.Blue, rect)
RectangleF rect = new RectangleF(50, 50, 100, 15);
Font font = new Font("Arial", 10, FontStyle.Underline);
_c1pdf.AddLink("https://www.grapecity.com/", rect);
_c1pdf.DrawString("Visit ComponentOne", font, Brushes.Blue, rect);

Here is the resulting PDF document:


You can also add local links, which when clicked take the user to another location within the same PDF document. This type of link is useful when you want to implement some type of cross-referencing within the document, such as a table of contents or an index.

Local links are identical to regular hyperlinks, except for two things: