3

I am using pdf js express to draw highlight annotation in pdf. But when I couldn't delete the annotation from the pdf. I am using this code to create highlight:

  const { Annotations, annotManager } = instance;
  citations.forEach((citation) => {
    if (citation.quads && isNumber(citation.page) && !isNaN(parseInt(citation.id))) {
      const citationAuthor = citation.created_by && citation.created_by.user
        ? `${citation.created_by.user.first_name} ${citation.created_by.user.last_name}`.trim()
        : author;
  
      const highlight = new Annotations.TextHighlightAnnotation();
      highlight.Author = citationAuthor;
      highlight.Quads = citation.quads;
      highlight.PageNumber = citation.page;
      highlight.Id = citation.id.toString();
      highlight.Locked = true;
      highlight.Subject = 'Citation';
      annotManager.addAnnotation(highlight, true);
      annotManager.drawAnnotations(highlight.PageNumber);
    }
  });

I am not finding any way to delete highlight annotation which will basically remove the highlight from the pdf

ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
  • 1
    The fastest way to get an answer to pdfjs.express questions is to post on the forum there. https://pdfjs.community/c/technical-support/7 – Ryan Nov 02 '20 at 22:22

1 Answers1

3

You will have to get Annotations object first and then delete highlight annotation by using deleteAnnotation API . Try following :

highlight = annotManager.getAnnotationById( yourCitationId);
annotManager.deleteAnnotation(highlight)
Md. Mahmud Hasan
  • 1,033
  • 1
  • 7
  • 24