This tutorial directs how to remove hyperlink from PDF in C#. You will get all the details required to set the development environment, a set of steps to be followed while developing the application and a runnable sample code to remove link from PDF in C# such that none of the hyperlinks is left. This operation does not require any third-party tool or software to be installed on the system while running this application.
Steps to Remove All Hyperlinks from PDF in C#
- Set the development environment to use Aspose.PDF for .NET to remove links
- Load the sample PDF file using the Document class object having multiple hyperlinks in it
- Parse through each page and access the collection of annotations on each page
- Parse through all the annotations and find the link type annotations
- Call the Delete() method from the Annotations collection class to remove the hyperlink
- Save the resultant PDF file having no hyperlinks in it
These steps provide consolidated information to remove hyperlink from PDF in C#. The process is commenced by loading the target PDF file and then parsing the annotations collection of each page to find the Link type annotation. Once the hyperlink annotation is found, it is deleted by calling the Delete() method of the AnnotationsCollection class.
Code to Remove Links from PDF Document in C#
The aforementioned code demonstrates the process of how to remove link from PDF in C# such that the hyperlink text remains there however only the link is removed. You can search different types of annotations like text, circle, polygon, polyline, line, square, free text, highlight, underline etc. If you want to delete entire annotations irrespective of the type, call the Delete() method without any arguments.
This quick tutorial has taught us how to develop a PDF hyperlink remover in C#. If you want to learn the process to add a hyperlink in a PDF, refer to the article on how to add hyperlink in PDF using C#.