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 Rect 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:

      Visual Basic

      C#

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:

      The url parameter must start with a "#".

      You must specify the target location for the link using the AddTarget method. The AddTarget method takes the same parameters as AddLink, a string that specifies the name of the target and a rectangle that marks the area on the page that will be displayed when the user selects the link.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.