如何在react中使用pdf js express从pdf中删除高亮注释



我正在使用pdf js express在pdf中绘制高亮注释。但当我无法从pdf中删除注释时。我用这个代码来创建亮点:

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

我没有找到任何方法来删除突出显示注释,这将基本上从pdf 中删除突出显示

您必须首先获取Annotations对象,然后使用deleteAnnotation API删除高亮注释。尝试以下操作:

highlight = annotManager.getAnnotationById( yourCitationId);
annotManager.deleteAnnotation(highlight)

最新更新