How to Remove Hyperlink in PDF using Java

This tutorial is designed to guide you on how to remove hyperlink in PDF using Java. It has all the details to configure the environment, a list of steps to write the desired application and a runnable sample code to clarify and demonstrate the operation to remove all hyperlinks from PDF using Java. You will also get details to delete other types of annotations and remove the particular link annotation only.

  1. Set the environment to use Aspose.PDF for Java to remove links
  2. Open the target PDF file using the Document class object to delete hyperlinks
  3. Iterate through all the PDF pages and access the annotations collection
  4. Iterate through all the annotations and identify the link type annotations only
  5. Call the delete() method to remove the hyperlink during the iteration
  6. Save the resultant PDF file on the disk after removing all the links

These steps enlighten us on how to remove hyperlink from PDF using Java. To commence the process, you have to open the source PDF file having hyperlinks in it using the Document class object and iterate through all the pages where each page has a separate collection of annotations. In the next step, iterate through the annotations and filter the link type annotations for deletion.

This code can be used as a base code for writing a bare-minimum application to delete hyperlink in PDF using Java. You may use annotation type to select the link type annotations that denote the hyperlinks and further filter the annotations based on different properties like flags, width, height, enclosing rectangle, contents, color, active state full name, and appearance if required. You may delete the selected annotation by providing the index number or delete the entire collection at once by calling the delete() method without any argument.

This article has defined the process of how to remove a hyperlink from a PDF using Java. If you want to learn the process to add watermark to a PDF, refer to the article on how to add watermark to PDF using Java.

 English