Delete Selected Annotation click on list item

Product:
Android java

Product Version:
PDFViewCtrl V7.0.0

Please give a brief summary of your issue:
(Think of this as an email subject)
Hi team,

delete Selected Annotation

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)

Please provide a link to a minimal sample where the issue is reproducible:

public void eraseSelectedAnnotation(int pos) {
if (mPdfViewCtrl == null) {
return;
}

    boolean shouldUnlock = false;
    try {
        mPdfViewCtrl.docLock(true);
        shouldUnlock = true;

        int currentPage = mPdfViewCtrl.getCurrentPage();
        Page page = mPdfViewCtrl.getDoc().getPage(currentPage);

        // Get the selected annotation at the specified position
        Annot selectedAnnotation = page.getAnnot(pos);

        if (selectedAnnotation != null) {
            // Remove the selected annotation
            page.annotRemove(selectedAnnotation);
            mPdfViewCtrl.update(true);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (shouldUnlock) {
            mPdfViewCtrl.docUnlock();
        }
    }
}

The above Code works fine to Delete specific Annotation item, we used blow features

But my issue is AddText over pdf

→ ToolMode toolMode = ToolMode.TEXT_CREATE; - Delete Annotation Not working ?
->ToolMode toolMode = ToolMode.RECT_CREATE; - Delete Annotation wrking
->ToolMode toolMode = ToolMode.INK_CREATE; - Delete Annotation wrking

Ref. Data:
{“Action”:“Add text box”,“Action event”:“add_free_text”,“Annot Info”:“{"Page Numbers":"1 ","Rects":"297 703 344 726 "}”}

so how can I delete it?

Check VIDEO Links:-

1 Like

Hello,

I think the two FreeTexts in your video fails to delete because the position is jumping as you are entering the value:
For example, the B text, notice the shift between adding the FreeText.

image
image

This is likely causing this line to not work:
Annot selectedAnnotation = page.getAnnot(pos);

This appears to be related to your custom implementation as the soft keyboard should not be pushing the FreeText box around you can verify the behaviour on our Showcase demo app

Thanks,
Andrew

2 Likes

Thanks, Andrew for replay.

This is likely causing this line to not work:
Annot selectedAnnotation = page.getAnnot(pos);

that’s right way… :+1: you find out

but my question is. this way is right to delete specific annotations?

if yes then tell me some more suggestions to delete annotations.

i have used old Android SDK used. but no way to or found delete specific annotations.

require to any of my below code snippet changes

but my equation is which changes require the below code

** int currentPage = mPdfViewCtrl.getCurrentPage();**
** Page page = mPdfViewCtrl.getDoc().getPage(currentPage);**

** // Get the selected annotation at the specified position**
** Annot selectedAnnotation = page.getAnnot(pos);**

** if (selectedAnnotation != null) {**
** // Remove the selected annotation**
** page.annotRemove(selectedAnnotation);**
** mPdfViewCtrl.update(true);**
** }**

And one more thing PDFTron document is updated… no found any code to delete specific annotations. and below of package not found

implementation project(‘:PDFViewCtrlTools’)

1 Like

Hello,

The issue is that the index is not a good way to retrieve your annotation, as it can change when you make modifications to the document (such as adding or removing annotations).

We recommend for you to instead store the ID for the annotation to ensure the lookup is correct, for example:
Annot.getUniqueID().getAsPDFText()

To retrieve via this ID you can call:
ViewerUtils.getAnnotById(PDFDoc doc, String id, int page num)

And then to properly delete this annot call:
AnnotUtils.safeDeleteAnnotAndUpdate(PDFViewCtrl pdfViewCtrl, Annot annot, int pageNum)

Please give this a try and see if it resolves your issue.

Thanks,
Andrew

2 Likes