Some test text!

menu
Remove annotationskeyboard_arrow_down

Deleting annotations in Android

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

The PDFTron library has an annotation list dialog fragment. The dialog fragment allows users to delete annotations easily. For more information, see annotation dialog fragment.
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.

linkDelete an annotation

To delete an annotation, you need to lock PDFViewCtrl first. See the section on document locking for more information.

You can delete an annotation as follows:

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);
        }
    });
}

linkDelete 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.

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);
        }
    });
}

linkDelete 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.

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);
        }
    });
}

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our upcoming webinar to find out about built-in, full-functioning document capabilities directly in Salesforce.

Save your seat
close