How to remove the hyperlinks from WinForms PDF using C# and VB.NET?
Syncfusion Essential® PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can remove the hyperlinks (URI annotation and WebLink annotation) from the PDF document in C# and VB.NET.
Steps to remove hyperlink from PDF programmatically:
- Create a new C# console application project.
2. Install the Syncfusion.Pdf.WinForms NuGet packages as reference to your .NET Framework application from NuGet.org.I hope you enjoyed learning how to preview UI changes using Ribbon Gallery.
3. Include the following namespaces in the Program.cs file.
C#
using Syncfusion.Pdf; using Syncfusion.Pdf.Interactive; using Syncfusion.Pdf.Parsing;
VB.NET
Imports Syncfusion.Pdf Imports Syncfusion.Pdf.Interactive Imports Syncfusion.Pdf.Parsing
- Use the following code snippet to remove hyperlink from the PDF document.
C#
//Load the existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf"); for (int i = 0; i < loadedDocument.Pages.Count; i++) { //Get the loaded page PdfLoadedPage page = loadedDocument.Pages[i] as PdfLoadedPage; for (int j = page.Annotations.Count - 1; j >= 0; j--) { if (page.Annotations[j] is PdfLoadedUriAnnotation || page.Annotations[j] is PdfLoadedTextWebLinkAnnotation) { //Removes the annotation page.Annotations.RemoveAt(j); } } } //Save the document loadedDocument.Save("Hyperlink.pdf"); //Close the document loadedDocument.Close(true); //This will open the PDF file so, the result will be seen in default PDF viewer Process.Start("Hyperlink.pdf");
VB.NET
'Load the existing PDF document Dim loadedDocument As New PdfLoadedDocument("Input.pdf") For i As Integer = 0 To loadedDocument.Pages.Count - 1 'Get the loaded page Dim page As PdfLoadedPage = TryCast(loadedDocument.Pages(i), PdfLoadedPage) For j As Integer = page.Annotations.Count - 1 To 0 Step -1 If TypeOf page.Annotations(j) Is PdfLoadedUriAnnotation OrElse TypeOf page.Annotations(j) Is PdfLoadedTextWebLinkAnnotation Then 'Removes the annotation page.Annotations.RemoveAt(j) End If Next Next 'Save the document loadedDocument.Save("Hyperlink.pdf") 'Close the document loadedDocument.Close(True) 'This will open the PDF file so, the result will be seen in default PDF viewer Process.Start("Hyperlink.pdf")
A complete working sample can be downloaded from RemoveHyperlinkSample.zip.
However, Acrobat Reader has a feature to predict the URL’s text and make it clickable. Please find the steps to disable the behavior.
Acrobat Reader > Edit > Preferences > General > Uncheck links from URLs.
Take a moment to peruse the documentation for working with hyperlink, where you can find the options like web navigation, internal, and external document navigation.
Refer here to explore the rich set of Syncfusion Essential® PDF features.
Note:
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion® license key in your application to use the components without trail message.
Conclusion
I hope you enjoyed learning about how to remove the hyperlinks from WinForms PDF using C# and VB.NET.
You can refer to our WinForms PDF feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms PDF example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!