Working with Hyperlinks in Windows Forms PDF Viewer (PdfViewerControl)
23 Sep 2020 / 3 minutes to read
PDF Viewer provides support for URLs (hyperlinks) in the PDF document that enables the navigation to the destination by opening it in the default browser just by clicking on it. This also supports a few events that are listed in the below table.
Events Table
Event | Description | Arguments | Type |
---|---|---|---|
This event is triggered when the mouse pointer is placed over the URL. | N/A | N/A | |
This event is triggered when the URL in the PDF document is clicked. | N/A | N/A |
How to disable hyperlink navigation in PDF Viewer?
We can disable the hyperlink navigation in PdfViewerControl by wiring the event HyperlinkClicked. The below code example illustrates the same.
//Initialize PDF Viewer.
PdfViewerControl pdfViewerControl = new PdfViewerControl();
//Load the PDF.
pdfViewerControl.Load("Sample.pdf");
// Hooks the event handler for `HyperlinkClicked` event.
pdfViewerControl.HyperlinkClicked += PdfViewerControl_HyperlinkClicked;
public void PdfViewerControl_HyperlinkClicked(object sender, AnnotEventArgs e)
{
//Your code here...
}
' Hooks the event handler for `HyperlinkClicked` event
'Initialize PDF Viewer.
Private pdfViewerControl As New PdfViewerControl()
'Load the PDF.
pdfViewerControl.Load("Sample.pdf")
AddHandler pdfViewerControl.HyperlinkClicked, AddressOf PdfViewerControl_HyperlinkClicked
Private Sub PdfViewerControl_HyperlinkClicked(obj As Object, args As Syncfusion.Windows.PdfViewer.AnnotEventArgs)
'Your code here...
End Sub
How to retrieve the clicked URL details from PDF Viewer?
We can acquire the details of the URL which is clicked in the PDF file using the the AnnotEventArgs, which is passed as a parameter of the HyperlinkClicked event. The below code example illustrates the same.
// Hooks the event handler for `HyperlinkClicked` event.
pdfViewerControl.HyperlinkClicked += PdfViewerControl_HyperlinkClicked;
public void PdfViewerControl_HyperlinkClicked(object sender, AnnotEventArgs e)
{
//Returns the URI clicked in the PDF viewer control.
string URI = args.URI;
}
' Hooks the event handler for `HyperlinkClicked` event
AddHandler pdfViewerControl.HyperlinkClicked, AddressOf PdfViewerControl_HyperlinkClicked
Private Sub PdfViewerControl_HyperlinkClicked(obj As Object, args As Syncfusion.Windows.PdfViewer.AnnotEventArgs)
' Returns the URI clicked in the PDF viewer control.
Dim uri As String = args.URI
End Sub
How to redirect to a different URL?
We can navigate to different URL irrespective of the one clicked. The below code example illustrates the same.
// Hooks the event handler for `HyperlinkClicked` event.
pdfViewerControl.HyperlinkClicked += PdfViewerControl_HyperlinkClicked;
public void PdfViewerControl_HyperlinkClicked(object sender, AnnotEventArgs e)
{
// Opens the URI (www.google.com) in a default browser.
System.Diagnostics.Process.Start("www.google.com");
}
' Hooks the event handler for `HyperlinkClicked` event.
AddHandler pdfViewerControl.HyperlinkClicked, AddressOf PdfViewerControl_HyperlinkClicked
Private Sub PdfViewerControl_HyperlinkClicked(obj As Object, args As Syncfusion.Windows.PdfViewer.AnnotEventArgs)
' Opens the URI (www.google.com) in a default browser.
System.Diagnostics.Process.Start("www.google.com")
End Sub
Was this page helpful?
Yes
No
Thank you for your feedback!
Thank you for your feedback and comments. We will rectify this as soon as possible!
An unknown error has occurred. Please try again.
Help us improve this page