Annotations
RadPdfViewer supports Link annotations, which 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 view port will be scrolled to the destination specified in the link.
The current API includes the following members, which allow customization of the default behavior or implementing custom logic:
- AnnotationClicked event of RadPdfViewer:This event is fired when you click on an annotation such as a hyperlink. It comes handy when you want to detect or even cancel the opening of a web page. The AnnotationEventArgs contain 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.
private void viewer_AnnotationClicked(object sender, AnnotationEventArgs e)
{
Link l = e.Annotation as Link;
if (l == null)
{
return;
}
UriAction a = l.Action as UriAction;
if (a == null)
{
return;
}
MessageBox.Show(a.Uri.ToString());
e.Handled = true;
}
- Annotations property of RadFixedDocument – a collection which returns all annotations in the document. For example you can retrieve all links using the following code:
private IEnumerable<Link> GetAllLinks(RadFixedDocument document)
{
foreach (Annotation a in document.Annotations)
{
Link l = a as Link;
if (l != null)
{
yield return l;
}
}
}
private IEnumerable<Destination> GetAllBookmarks(RadFixedDocument document)
{
foreach (Annotation a in document.Annotations)
{
Link l = a as Link;
if (l != null && l.Destination != null)
{
yield return l.Destination;
}
}
}
private void GoToDestination(Destination destination)
{
this.pdfViewer.GoToDestination(destination);
}
Destination myDestination = new Location() { Page = this.pdfViewer.Document.Pages[2], Left = 0, Top = 0, Zoom = 1 };