Hyperlink in UWP PDF Viewer (SfPdfViewer)
14 Jul 20265 minutes to read
The PDF Viewer control supports hyperlink navigation that detects document links and web links present in the PDF document pages. Tapping a table of contents (TOC) entry or hyperlink behaves as follows:
1) If the tapped text contains a web link, the URI associated with the hyperlink is opened in the default browser.
2) If the tapped text contains a document link, the PDF Viewer navigates to the associated destination page index.
How to disable hyperlink navigation in PDF document using PDF Viewer control?
You can disable hyperlink navigation by setting the AllowHyperlinkNavigation property of the PDF Viewer to false. By default, hyperlink navigation is enabled in the PDF Viewer.
<syncfusion:SfPdfViewerControl x:Name="pdfViewerControl" AllowHyperlinkNavigation="False"/>How to acquire the properties of clicked URI from PDF Viewer?
You can acquire the details of the hyperlink that is tapped in the PDF Viewer control from the HyperlinkEventArgs of the HyperlinkPointerPressed event. Refer to the following code example for more details.
<syncfusion:SfPdfViewerControl x:Name="pdfViewerControl" HyperlinkPointerPressed="pdfViewerControl_HyperlinkPointerPressed"/>public void pdfViewerControl_HyperlinkPointerPressed(object sender,HyperlinkEventArgs args)
{
// Gets or sets a value indicating whether the hyperlink navigation was handled.
args.Handled = false;
// Gets the hyperlink being clicked.
string uri = args.URI;
// Gets the current page index of the hyperlink.
int pageIndex = args.PageIndex;
// Gets the destination page index of the hyperlink.
int destinationPageIndex = args.DestinationPageIndex;
// Gets the bounds of the hyperlink being clicked.
RectangleF hyperlinkBound = args.Bounds;
// Gets whether the tapped hyperlink is a Web Link or Document Link.
HyperlinkType linkType = args.HyperlinkType;
}How to detect whether the mouse pointer is over the hyperlink text?
The HyperlinkPointerMoved event is raised when the mouse pointer is moved over the hyperlink text. Refer to the following code example for more details.
<syncfusion:SfPdfViewerControl x:Name="pdfViewerControl" HyperlinkPointerMoved="pdfViewerControl_HyperlinkPointerMoved"/>public void pdfViewerControl_HyperlinkPointerMoved(object sender,HyperlinkEventArgs args)
{
// Gets or sets a value indicating whether the hyperlink navigation was handled.
args.Handled = false;
// Gets the hyperlink under the pointer.
string uri = args.URI;
// Gets the current page index of the hyperlink.
int pageIndex = args.PageIndex;
// Gets the destination page index of the hyperlink.
int destinationPageIndex = args.DestinationPageIndex;
// Gets the bounds of the hyperlink under the pointer.
RectangleF hyperlinkBound = args.Bounds;
//Gets the whether the tapped hyper link is a Web Link or Document Link.
HyperlinkType linkType = args.HyperlinkType
}How to restrict the URI navigation from the PDF Viewer?
By default, web link or document link navigation is performed on tapping the hyperlink text. This navigation can be restricted using the Handled property of the HyperlinkEventArgs. Refer to the following code snippet for more details.
public void pdfViewerControl_HyperlinkPointerPressed(object sender,HyperlinkEventArgs args)
{
// Setting the property to true will restrict the URI navigation inside the PDF Viewer control. By default, the value is false.
args.Handled = true;
}