Hyperlink navigation in .NET MAUI PDF Viewer (SfPdfViewer)

2 Aug 20231 minute to read

The SfPdfViewer allows you to open URLs or website links in the default browser. When a user taps or clicks a hyperlink on a PDF page, the SfPdfViewer recognizes the link and prompts a hyperlink dialog asking the user if they want to open the link.

The HyperlinkClicked event occurs when a hyperlink is tapped or clicked and allows you to handle the hyperlink navigation at the application level in your way. Set the Handled property of the HyperlinkClickedEventArgs to true to suppress the default hyperlink dialog and handle your logic with the hyperlink information. The following example explains how to open a link directly in the system default browser without confirmation prompts.

<syncfusion:SfPdfViewer 
	x:Name="PdfViewer"
	HyperlinkClicked="PdfHyperlinkClicked"/>
public MainPage()
{
	InitializeComponent();
	PdfViewer.HyperlinkClicked += PdfHyperlinkClicked;
}

private async void PdfHyperlinkClicked(object sender, HyperlinkClickedEventArgs e)
{
	e.Handled = true;
	await Browser.Default.OpenAsync(e.Uri, BrowserLaunchMode.SystemPreferred);
}

Enable or disable the recognition of hyperlinks in PDF documents using the EnableHyperlinkNavigation property. The following code explains the same.

<syncfusion:SfPdfViewer 
	x:Name="PdfViewer" 
	EnableHyperlinkNavigation="False"/>
PdfViewer.EnableHyperlinkNavigation = false;