Notes Panel Shows Incorrect Annotation Count When Importing XFDF in Chunks Using importAnnotationCommand

WebViewer Version: 11.7.1

Do you have an issue with a specific file(s)?
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?

Please give a brief summary of your issue:
Notes Panel Shows Incorrect Annotation Count When Importing XFDF in Chunks Using importAnnotationCommand

Please describe your issue and provide steps to reproduce it:

When loading annotations from the database in chunks and importing XFDF using annotationManager.importAnnotationCommand, the Notes panel displays a higher annotation count than the number of annotations actually rendered on the document.

Example:

  • API returns 50 annotations

  • Only 50 annotations are visually rendered

  • Notes panel shows 75 / 200+ comments

Expected Behavior

  • Notes panel count should match the number of unique annotations imported and rendered.

  • Importing 50 annotations should result in 50 notes.

Actual Behavior

  • Notes panel count increases unexpectedly.

  • The count jumps by tens or hundreds, even though only a few annotations are visible on the page.

  • This happens specifically during chunked XFDF imports.

Key Findings (Important)

After investigation, we found:

  1. importAnnotationCommand() does not guarantee a 1:1 mapping between:

    • One XFDF input

    • One annotation object created

  2. Some XFDF commands appear to:

    • Replay <add> or <modify> operations

    • Re-apply changes to existing annotations

    • Create additional internal annotation objects

  3. As a result:

    • The document visually shows the correct annotations

    • The Notes panel counts all internal annotation objects, including duplicates or overwritten ones

  4. Concatenating multiple XFDF strings into a single call significantly amplifies the issue and causes massive inflation in Notes panel count.

What Does NOT Work

  • Concatenating multiple XFDF strings into one importAnnotationCommand

  • Skipping importAnnotationCommand and trying to manipulate XFDF directly

  • Applying styles without importing annotations into annotationManager

importAndStyleChunk: async function (annotations) {
    const self = this;
    self.showAnnotationLoader();
    const annotationManager = window.webViewerInstance.Core.annotationManager;
    for (const a of annotations) {
        const importedAnnots = await annotationManager.importAnnotationCommand(a.annotData);

        importedAnnots.forEach(annot => {
            annot.setContents(a.text);
            self.applySecuritySettings(annot);
            annotationManager.redrawAnnotation(annot);
        });

        await new Promise(resolve => requestAnimationFrame(resolve));
    }
},

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

Hello, I’m AiRon, an automated tech support bot :robot:
While you wait for one of our customer support representatives, I can help you with your question.


It seems like you’re encountering an issue with the Notes panel showing an incorrect annotation count when importing XFDF in chunks using importAnnotationCommand. This can happen due to the way XFDF commands are processed, where operations like <add> or <modify> can lead to duplicate internal annotation objects being counted in the Notes panel.

Some things you can try:

  • Ensure that each XFDF string being imported is distinct and correctly formatted to avoid any replay or duplication of modifications.

  • Consider using importAnnotations instead of importAnnotationCommand if you’re dealing with large batches, as it might handle the state more cleanly.

  • After each import, use the redrawAnnotation method to refresh the document and ensure the annotations are displayed correctly.

  • Check if the annotations are being uniquely identified by attributes like IDs, to prevent them from being miscounted as duplicates.

  • Investigate if the annotationManager’s internal state needs a reset or cleanup between imports to prevent accumulation of stale data.



Here are some resources that might help you:


Hopefully, this helps you solve your problem while you wait for a human to get back to you.

Hello @rishumishra2001,

Thank you for posting on our forum.

After some initial testing, we were unable to reproduce the issue on our end. To investigate further, please confirm the following:

  1. XFDF string(s) used for testing
  2. Are you able to reproduce this issue on our latest release (Version 11.9.1)?
  3. Demo video reproducing the issue, highlighting expected vs. actual behavior and/or screenshots
  4. Can you reproduce the issue using our samples (especially on our site)? https://sdk.apryse.com/samples/web/samples/viewing/viewing/
  5. What is the use case behind using importAnnotationCommand to batch import annotations? Typically for this type of workflow we would recommend the importAnnotations/exportAnnotations APIs
  6. PDF used for testing
  7. What is returned when calling annotationManager.getAnnotationsList()? Is it the 50 imported or the 75/200+ reported in the notes panel?

Best Regards,
Jacob Romano Carlsen
Web Development Support Engineer
Apryse Software Inc.\