Link Annotations
PdfViewer provides read-only support for link annotations. This means that if you open a PDF file that includes hyperlinks to absolute URIs, you can click them and have a window open, navigated to the respective address. In addition, if there are links pointing to bookmarks in the same document, the viewport will be scrolled to the destination specified in the link.
Link annotations are part of the Telerik RadPdfProcessing library which is used for the document model of the PdfViewer control.
Clicked link annotation
To get the link annotations available in the document, you can use the Annotation
collection property of RadFixedDocument
.
Get the annotations
IEnumerable<Link> annotations = this.pdfViewer.Document.Annotations.OfType<Link>();
// the address of the link annotation can be access via its Action property
Link link = annotations.ElementAt(0);
UriAction action = (UriAction)link.Action;
Uri address = action.Uri;
Destination destination = action.Destination;
Action
property. The Uri
property of the action tells what is the external address that the annotation click should open. The Destination
points to a bookmark within the loaded document.
To replace or cancel the action that happens on link click, you can use the AnnotationClick
event of RadPdfViewer
.
Cancel link click navigation
private void PdfViewer_AnnotationClicked(object sender, Telerik.Windows.Documents.Fixed.Model.Annotations.EventArgs.AnnotationEventArgs e)
{
// cancel the go-to action of the link
e.Handled = true;
RadFixedPage page = e.Page;
Link link = (Link)e.Annotation;
//here you can implement any custom logic that should happen on annotation click
}