This article describes the process on how to remove hyperlink from PDF using Python. It contains details about configuring the development environment, a list of steps to develop the application and a runnable sample code to remove all hyperlinks from PDF using Python. You will also learn different customization options while removing the hyperlinks from selected pages if required.
Steps to Delete Hyperlink in PDF using Python
- Set the IDE to use Aspose.PDF for Python via .NET to remove hyperlinks
- Load the source PDF with hyperlinks using the Document class object
- Parse through all the pages one by one to get collections of annotations
- Check each annotation having type LINK
- Call the delete() method of the annotations collection
- Save the output PDF after removing the hyperlinks
These steps encompass the procedure to develop PDF hyperlink remover using Python. Each page in the PDF contains a collection of annotations of different types including LINK. In this process, all the pages in a PDF file are iterated where each annotation is tested against the annotation type LINK that is subsequently deleted using the delete() method in the annotations collection.
Code to Remove Link from PDF using Python
This code demonstrates the process to remove links from PDF document using Python. All the annotations on each page are parsed and checked for type AnnotationType.LINK as it denotes the hyperlink. Once the hyperlink is detected, it is deleted by calling the delete() method that deletes the hyperlink only whereas the text and its formatting are retained however you may customize the text formatting by setting different properties of the annotation before deleting it.
This article has guided us on how in PDF remove hyperlinks using Python. If you want to learn the process of adding hyperlinks in a PDF, refer to the article on how to add hyperlink in PDF using Python.