Hyperlink Navigation in Xamarin Pdf Viewer (SfPdfViewer)

4 Jan 20232 minutes to read

Xamarin PDF Viewer supports hyperlink navigation that detects hyperlinks and tapping on the hyperlink will open the URL in the browser.

You can disable the hyperlink navigation by setting the “AllowHyperlinkNavigation” property of PDF viewer to false. By default, hyperlink navigation is enabled in PDF viewer.

<syncfusion:SfPdfViewer x:Name="pdfViewerControl" AllowHyperlinkNavigation="False" InputFileStream="{Binding PdfDocumentStream}" />

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 HyperlinkClickedEventArgs and HyperlinkClicked event. Refer to the following code snippet for more details.

<syncfusion:SfPdfViewer x:Name="pdfViewerControl" HyperlinkClicked="pdfViewerControl_HyperlinkClicked"  InputFileStream="{Binding PdfDocumentStream}" />
public void pdfViewerControl_HyperlinkClicked(object sender,HyperlinkClickedEventArgs 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 bounds of the hyperlink is being clicked.
            Rectangle hyperlinkBound = args.Bounds;
        }

NOTE

You can also explore our Xamarin.Forms PDF Viewer example to knows the functionalities of each feature.