This short tutorial describes how to remove annotations from PDF in Java. It contains the settings for the IDE, a list of tasks, and a running sample code to remove PDF annotations in Java. You will learn to delete all or selected annotations based on your requirements.
Steps to Delete Annotations from PDF in Java
- Set the environment to use Aspose.PDF for Java to remove annotations
- Load the target PDF file into the Document object providing the file name
- Access the target page from the collection of the pages in the loaded document
- Access the annotations collection of the page and call the delete() method
- Save the output PDF after deleting the annotations
These steps define the process to remove all annotations from PDF in Java. Each page in the PDF contains an object of the AnnotationCollection that supports the removal of annotations using the delete() method. You may iterate through all the pages in the PDF to delete annotations from the entire PDF.
Code to Delete Annotation in PDF in Java
The above code demonstrates a PDF annotation remover in Java. You can use the delete() method with an index number to delete a particular annotation. Another option is to delete an annotation by providing it as an argument to the delete method.
This article has taught us how to remove all annotations from PDF in Java. If you want to highlight some text in a PDF, refer to the article on how to highlight a PDF document using Java.