This article guides how to remove highlight from PDF using Java. It contains details to set the development environment, a list of steps, and a sample code showing how to remove highlight in PDF using Java. You will learn to filter different types of annotations and delete them as per the requirements.
Steps to Remove Highlight on PDF using Java
- Set the environment to use Aspose.PDF for Java to erase highlights
- Load the input PDF file into the Document object with highlights in it with different colors
- Get the collection of the pages in the PDF file and parse through the collection of annotations in it
- Process each highlight annotation and cast it to the HighlightAnnotation class
- Check the annotation and mark it for deletion as per the user input
- Delete the annotation using the delete() method in the Annotations collection accessed through getAnnotations()
- Save the output PDF file after processing the highlights in the PDF
The above steps summarize how to delete highlights in PDF using Java. Import the required modules from the library, create an enumerator, load the license, and define the method that gets the arguments, such as input PDF, output PDF, type of removal, i.e., all or specific color, and the color if required. Finally, access the highlight annotations in the PDF and delete them based on input parameters.
Code to Remove PDF Highlight using Java
This code has demonstrated how to erase highlight in PDF using Java. Each annotation in a page is converted to HighlightAnnotation, as the color property might be required to remove the highlight. If you want to remove all the annotations, do not use this casting to HighlightAnnotation and just delete the annotation directly without any condition.
This article has taught us the process to find and remove the highlight annotation. To convert a PDF file to a PDF, refer to the article Convert a PS File to PDF using Java.