Java remove annotations from PDF

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:

Java remove annotations from PDF

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();
        ////Remove the first annotation from the first page of PDF
        //Remove all annotations

        String result = "output/deleteAllAnnotations_out.pdf";

        //Save the document

Effective screenshot after delete all the annotations:

Java remove annotations from PDF