> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/android/annotation/delete-annot.md).

# Deleting annotations in Android

Learn how to efficiently delete annotations in PDF documents using the Apryse library. Easily delete single or all annotations on a page or in a document. Keep track of page numbers for quick deletion

Using the Apryse library, you can delete a single annotation, delete all the annotations on a page, or delete all the annotations in a PDF document.

{% hint style="info" %}
The Apryse library has an annotation list dialog fragment. The dialog fragment allows users to delete annotations easily. For more information, see [annotation dialog fragment ](/android/annotation/annotation-list-a.md).
{% endhint %}

{% hint style="warning" %}
To delete an annotation, you need the page number of the annotation. To avoid looping through the whole document to find the page number of the annotation, we recommend you always keep track of the page number when you get an annotation.
{% endhint %}

## Delete an annotation

{% hint style="info" %}
To delete an annotation, you need to lock `PDFViewCtrl` first. See the section on [document locking](/android/open-save-document/lock.md) for more information.
{% endhint %}

You can delete an annotation as follows:

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
public void deleteAnnotation(final PDFViewCtrl pdfViewCtrl, final Annot annot, final int pageNum) throws Exception {
    // Lock the document first, because accessing annotation/doc information isn't thread-safe.
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            Page page = pdfViewCtrl.getDoc().getPage(pageNum);
            page.annotRemove(annot);
            pdfViewCtrl.update(annot, pageNum);
        }
    });
}
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
fun deleteAnnotation(pdfViewCtrl: PDFViewCtrl, annot: Annot?, pageNum: Int) { 
    // Lock the document first, because accessing annotation/doc information isn't thread-safe.
    pdfViewCtrl.docLock(true) {
        val page = pdfViewCtrl.doc.getPage(pageNum)
        page.annotRemove(annot)
        pdfViewCtrl.update(annot, pageNum)
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Delete all annotations on a page

The following snippet shows how to enumerate all the annotations on a page, as well as how to delete them.

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
void deleteAnnotationsOnPage(final PDFViewCtrl pdfViewCtrl, final int pageNum) throws Exception {
    // Lock the document first, because accessing annotation/doc information isn't thread-safe.
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            Page page = pdfViewCtrl.getDoc().getPage(pageNum);
            int annotCount = page.getNumAnnots();
            while (annotCount > 0) {
                page.annotRemove(0);
                annotCount = page.getNumAnnots();
            }
            pdfViewCtrl.update(true);
        }
    });
}
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
fun deleteAnnotationsOnPage(pdfViewCtrl: PDFViewCtrl, pageNum: Int) {
    // Lock the document first, because accessing annotation/doc information isn't thread-safe.
    pdfViewCtrl.docLock(true) {
        val page = pdfViewCtrl.doc.getPage(pageNum)
        var annotCount = page.numAnnots
        while (annotCount > 0) {
            page.annotRemove(0)
            annotCount = page.numAnnots
        }
        pdfViewCtrl.update(true)
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Delete all the annotations in a PDF document

The following snippet shows how to traverse all the pages in a PDF document and delete all the annotations.

{% tabs %}
{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
void deleteAllAnnotations(final PDFViewCtrl pdfViewCtrl) throws Exception {
    // Lock the document first, because accessing annotation/doc information isn't thread-safe.
    pdfViewCtrl.docLock(true, new PDFViewCtrl.LockRunnable() {
        @Override
        public void run() throws Exception {
            PDFDoc pdfDoc = pdfViewCtrl.getDoc();
            PageIterator itr = pdfDoc.getPageIterator();
            while (itr.hasNext()) {
                Page page = (Page) itr.next();
                int annotCount = page.getNumAnnots();
                while (annotCount > 0) {
                    page.annotRemove(0);
                    annotCount = page.getNumAnnots();
                }
            }
            pdfViewCtrl.update(true);
        }
    });
}
```

{% endcode %}
{% endtab %}

{% tab title="Kotlin" %}
{% code lineNumbers="true" %}

```kotlin
fun deleteAllAnnotations(pdfViewCtrl: PDFViewCtrl) { 
    // Lock the document first, because accessing annotation/doc information isn't thread-safe.
    pdfViewCtrl.docLock(true) {
        val pdfDoc = pdfViewCtrl.doc
        val itr = pdfDoc.pageIterator
        while (itr.hasNext()) {
            val page = itr.next()
            var annotCount = page!!.numAnnots
            while (annotCount > 0) {
                page.annotRemove(0)
                annotCount = page.numAnnots
            }
        }
        pdfViewCtrl.update(true)
    }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.apryse.com/android/annotation/delete-annot.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
