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="http://ns.adobe.com/xfdf/" 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:
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 = [...new 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
annotationManager.drawAnnotations({pageNumber})
})
// This line will refresh the pages that currently have annotations
annotationManager.drawAnnotationsFromList(annotationManager.getAnnotationsList())
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?
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.