PDF for UWP | ComponentOne
Using PDF for UWP / Adding Links to a PDF Document
In This Topic
    Adding Links to a PDF Document
    In This Topic

    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 C1PdfDocument.AddLink method. C1PdfDocument.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.

    The C1PdfDocument.AddLink method does not add any visible content to the page, so you will usually need another command along with C1PdfDocument.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.
       

    VB
    Copy Code
    Dim rect As New Rect(50, 50, 100, 15)
    
    Dim font As New Font("Arial", 10)
    
    pdf.AddLink("https://developer.mescius.com/", rect)
    
    pdf.DrawString("Visit ComponentOne", font, Colors.Blue, rect)
    

                

    Example Title
    Copy Code
    Rect rect = new Rect(50, 50, 100, 15);
    Font font = new Font("Arial", 10);
    pdf.AddLink("http://www.componentone.com", rect);
    pdf.DrawString("Visit ComponentOne", font, Windows.UI.Colors.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: