PDF for WPF and Silverlight Overview > Features: PDF for WPF and Silverlight > 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:
To write the code in Visual Basic:
Dim rect As New Rect(50, 50, 100, 15)
Dim font As New Font("Arial", 10, FontStyle.Underline)
_c1pdf.AddLink("http://www.componentone.com", rect)
_c1pdf.DrawString("Visit ComponentOne", font, Colors.Blue, rect)
To write the code in C#:
Rect rect = new Rect(50, 50, 100, 15);
Font font = new Font("Arial", 10, FontStyle.Underline);
_c1pdf.AddLink("http://www.componentone.com", rect);
_c1pdf.DrawString("Visit ComponentOne", font, Colors.Blue, rect);