We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to remove the hyperlinks from a PDF using C# and VB.NET

Platform: WinForms |
Control: PDF

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:

  1. Create a new C# console application project. Title: Create a console application project
  2. Install the Syncfusion.Pdf.WinForms NuGet packages as reference to your .NET Framework application from NuGet.org. Title: NuGet reference
  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

 

  1. 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. Title: screenshot for steps to disable the hyperlink

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.

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile