importAnnotations doesn't clear existing annotations when empty list is passed

WebViewer Version: 8.6.0

Do you have an issue with a specific file(s)? No
Can you reproduce using one of our samples or online demos?
Are you using the WebViewer server?
Does the issue only happen on certain browsers?
Is your issue related to a front-end framework?
Is your issue related to annotations? Yes

Please give a brief summary of your issue:
I have annotations in my document bucketed in several categories. The user can select a category from a drop-down (separate from the WebViewer component) and I pass the filtered list of annotations to the WebViewer to be displayed, replacing any annotations that were displayed prior to the user’s category selection. This is working fine in most cases, but when the user selects a category that doesn’t have any annotations, the WebViewer continues to show the previously displayed annotations (i.e. the “replace” operation appears to be skipped).

Please describe your issue and provide steps to reproduce it:
I’m calling importAnnotations like this: annotationManager.importAnnotations(xfdf, { replace : [Core.Annotations.Annotation] }) with the XFDF string for the empty list like this: <?xml version="1.0" encoding="UTF-8" ?><xfdf xmlns="" xml:space="preserve"><fields /><annots></annots><pages><defmtx matrix="1,0,0,-1,0,843" /></pages></xfdf> . Note that you must first load some annotations before passing the empty string in order to see the issue.

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

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:


Hi Ryan,

If you try zoom in after importing the empty annotation, you will see that the previous annotations are all gone as expected because the pages are “refreshed”.

It’s recommended to refresh annotations after importing. For your particular case, you can try:

// First, get all the page numbers of current annotations
const pageNumbers = annotationManager.getAnnotationsList().map(annot=>annot.PageNumber);

// But there can be duplicated page numbers if a page has multiple annotations, so lets remove the duplicate ones:
const pageNumbersOfOldAnnotations = [ Set(pageNumbers)]

// your xfdf importing logic here
annotationManager.importAnnotations(xfdf, { replace : [instance.Core.Annotations.Annotation] });

pageNumbersOfOldAnnotations.forEach(pageNumber=> {
  // This line will refresh the pages that previously had annotations
// This line will refresh the pages that currently have annotations

Thanks for the response Yixiao. Indeed after refreshing the old pages I no longer see the annotations appearing in the document, however they are still present in the notes panel - is there a way to similarly refresh that element?

You can use annotationManager.deleteAnnotations() so the code becomes

const pageNumbers = annotationManager.getAnnotationsList().map(annot=>annot.PageNumber);
const pageNumbersOfOldAnnotations = [ Set(pageNumbers)];


pageNumbersOfOldAnnotations.forEach(pageNumber=> {

The problem with calling deleteAnnotations is that it triggers an annotationChanged event, and my handler would treat this the same as a delete action by the user rather than just temporarily hiding the annotations. It looks like I am able to work around this by using the options argument in deleteAnnotations, but this feels like a hacky solution to a missed edge case. The ‘replace’ option works well for me in every other scenario, so I would expect it to work exactly the same when I’m replacing the current annotations with an empty list. I hope the development team will consider looking into this and addressing it in a future release.

That makes sense. I’m adding this to our backlog now.

1 Like