# Annotations

**RadPdfViewer** supports link annotations. External URI annotations open only when the destination passes both link-format and URI-scheme validation, or an application handler explicitly approves it. The default allowed schemes are `http`, `https`, and `mailto`. Links pointing to destinations in the same PDF document scroll the viewport internally.

The current API includes the following members, which allow customization of the default behavior or implementation of custom logic:

* **AnnotationClicked** event of **RadPdfViewer**: This event is fired when you click on an annotation such as a hyperlink. It comes in handy when you want to detect or even cancel the opening of a web page. The **AnnotationEventArgs** contains the Annotation as property and the Link itself has information of its Action, i.e. if it is a UriAction. Handling the event in the following manner will not only show the Uri of each clicked link as the text of a MessageBox but will also cancel the default behavior.

#### AnnotationClicked Event Handler

```C#
private void radPdfViewer1_AnnotationClicked(object sender, Telerik.Documents.Fixed.Model.Annotations.EventArgs.AnnotationEventArgs e)
{
    Telerik.Documents.Fixed.Model.Annotations.Link l = e.Annotation as Telerik.Documents.Fixed.Model.Annotations.Link;
    if (l == null)
    {
        return;
    }
    UriAction a = l.Actions[0] as UriAction;
    if (a == null)
    {
        return;
    }
    System.Windows.MessageBox.Show(a.Uri.ToString());
    e.Handled = true;
}
    
```

```VB.NET
Private Sub radPdfViewer1_AnnotationClicked(sender As Object, e As Telerik.Documents.Fixed.Model.Annotations.EventArgs.AnnotationEventArgs)
    Dim l As Telerik.Documents.Fixed.Model.Annotations.Link = TryCast(e.Annotation, Telerik.Documents.Fixed.Model.Annotations.Link)
    If l Is Nothing Then
        Return
    End If
    Dim a As Telerik.Documents.Fixed.Model.Actions.UriAction = TryCast(l.Actions(0), Telerik.Documents.Fixed.Model.Actions.UriAction)
    If a Is Nothing Then
        Return
    End If
    MessageBox.Show(a.Uri.ToString())
    e.Handled = True
End Sub

```

* `RadPdfViewer.HyperlinkClicked` is raised for URI annotation navigation. It uses `Telerik.WinControls.Hyperlinks.HyperlinkClickedEventArgs`, which exposes `URL`, `IsTrustedUrl`, and `Handled`. Set `IsTrustedUrl` to `true` only after applying your own destination validation. Set `Handled` to `true` to replace or suppress navigation.

If the local event leaves the request unhandled, `HyperlinkHelper.HyperlinkClicked` runs next. An unhandled request whose final `IsTrustedUrl` is `false` displays the localized invalid-link message. Setting `Handled` to `true` suppresses both the launch and the message. FTP, file/UNC, OneNote, and custom-protocol destinations are not automatically approved. See [shared hyperlink validation](https://www.telerik.com/products/winforms/documentation/telerik-presentation-framework/html-like-text-formatting#shared-hyperlink-validation) for the default policy and [handling links across controls](https://www.telerik.com/products/winforms/documentation/telerik-presentation-framework/html-like-text-formatting#handling-links-across-controls) for a global approval example.

The following example prompts the user before continuing navigation:

#### HyperlinkClicked Event Handler

```C#
private void RadPdfViewer1_HyperlinkClicked(object sender, Telerik.WinControls.Hyperlinks.HyperlinkClickedEventArgs e)
{
    var link = e.URL;
    if (link.EndsWith("exe"))
    {
        e.Handled = true; MessageBoxResult Result = System.Windows.MessageBox.Show("You are about to open an executable file. Do you want to proceed", "Possible unsafe link", MessageBoxButton.YesNo, MessageBoxImage.Question);
        if (Result == MessageBoxResult.Yes)
        {
            Process.Start(new ProcessStartInfo()
            {
                FileName = link,
                UseShellExecute = true
            });
        }
    }
}
```

```VB.NET
Private Sub RadPdfViewer1_HyperlinkClicked(sender As Object, e As HyperlinkClickedEventArgs)
    Dim link = e.URL
    If link.EndsWith("exe") Then
        e.Handled = True
        Dim Result As MessageBoxResult = System.Windows.MessageBox.Show("You are about to open an executable file. Do you want to proceed", "Possible unsafe link", MessageBoxButton.YesNo, MessageBoxImage.Question)
        If Result = MessageBoxResult.Yes Then
            Process.Start(New ProcessStartInfo() With {
                .FileName = link,
                .UseShellExecute = True
            })
        End If
    End If
End Sub
```

* **Annotations** property of **RadFixedDocument** – A collection which returns all annotations in the document. For example, you can retrieve all links using the following code:

#### Get Annotation Links

```C#
private IEnumerable<Telerik.Documents.Fixed.Model.Annotations.Link> GetAllLinks(Telerik.Documents.Fixed.Model.RadFixedDocument document)
{
    foreach (Telerik.Documents.Fixed.Model.Annotations.Annotation a in document.Annotations)
    {
        Telerik.Documents.Fixed.Model.Annotations.Link l = a as Telerik.Documents.Fixed.Model.Annotations.Link;
        if (l != null)
        {
            yield return l;
        }
    }
}
    
```

```VB.NET
Private Iterator Function GetAllLinks(document As Telerik.Documents.Fixed.Model.RadFixedDocument) As IEnumerable(Of Telerik.Documents.Fixed.Model.Annotations.Link)
    For Each a As Telerik.Documents.Fixed.Model.Annotations.Annotation In document.Annotations
        Dim l As Telerik.Documents.Fixed.Model.Annotations.Link = TryCast(a, Telerik.Documents.Fixed.Model.Annotations.Link)
        If l IsNot Nothing Then
            Yield l
        End If
    Next
End Function

```

The bookmarks in terms of “docx bookmarks” are not explicitly saved in PDF files. They are persisted only if there are Link annotations to them, so you can use the snippet below to retrieve all destinations that have links to them:

#### Get Annotation Bookmarks

```C#
private IEnumerable<Telerik.Documents.Fixed.Model.Navigation.Destination> GetAllBookmarks(Telerik.Documents.Fixed.Model.RadFixedDocument document)
{
    foreach (Telerik.Documents.Fixed.Model.Annotations.Annotation a in document.Annotations)
    {
        Telerik.Documents.Fixed.Model.Annotations.Link l = a as Telerik.Documents.Fixed.Model.Annotations.Link;
        if (l != null && l.Destination != null)
        {
            yield return l.Destination;
        }
    }
}
    
```

```VB.NET
Private Iterator Function GetAllBookmarks(document As Telerik.Documents.Fixed.Model.RadFixedDocument) As IEnumerable(Of Telerik.Documents.Fixed.Model.Navigation.Destination)
    For Each a As Telerik.Documents.Fixed.Model.Annotations.Annotation In document.Annotations
        Dim l As Telerik.Documents.Fixed.Model.Annotations.Link = TryCast(a, Telerik.Documents.Fixed.Model.Annotations.Link)
        If l IsNot Nothing AndAlso l.Destination IsNot Nothing Then
            Yield l.Destination
        End If
    Next
End Function

```

In this way, creating some UI containing all bookmarks would be possible. Then, you could implement the same action as the one being executed when a hyperlink is clicked, i.e. scroll the document to the specific place in the document where the destination of the link is placed. The following code can be used for this purpose – navigating to a specific destination:

#### Navigate to Destination

```C#
private void GoToDestination(Telerik.Documents.Fixed.Model.Navigation.Destination destination)
{
    this.radPdfViewer1.PdfViewerElement.GoToDestination(destination);
}
    
```

```VB.NET
Private Sub GoToDestination(destination As Telerik.Documents.Fixed.Model.Navigation.Destination)
    Me.RadPdfViewer1.PdfViewerElement.GoToDestination(destination)
End Sub

```

## See Also

* [Getting Started](https://www.telerik.com/products/winforms/documentation/controls/pdfviewer/getting-started)
* [Logical Structure](https://www.telerik.com/products/winforms/documentation/controls/pdfviewer/structure/logical-structure)
* [Visual Structure](https://www.telerik.com/products/winforms/documentation/controls/pdfviewer/structure/visual-structure)
* [Properties, Methods and Events](https://www.telerik.com/products/winforms/documentation/controls/pdfviewer/properties-methods-events)
