We have demonstrated how to use Spire.PDF for java to add annotation to PDF document. This article will demonstrate how to delete annotations from PDF document.
Firstly, view the sample PDF with annotations:
Spire.PDF supports to delete a specified annotation and it also supports to clear all the annotations at one time.
import com.spire.pdf.*; public class deleteAnnotation { public static void main(String[] args) throws Exception { //Load the sample PDF file PdfDocument document = new PdfDocument(); document.loadFromFile("annotations.pdf"); ////Remove the first annotation from the first page of PDF //document.getPages().get(0).getAnnotationsWidget().removeAt(0); //Remove all annotations document.getPages().get(0).getAnnotationsWidget().clear(); String result = "output/deleteAllAnnotations_out.pdf"; //Save the document document.saveToFile(result); } }
Effective screenshot after delete all the annotations: