Annotations not saving to the pdf

Which product are you using?
PDF.js Express Plus

PDF.js Express Version
8.7

Detailed description of issue
not able to save from back end (Java script) the pdf along with annotations

Expected behaviour
the saved pdf should include the annotation

Does your issue happen with every document, or just one?
every docuement

Link to document
{Provide a link to the document in question if possible}

Code snippet
const { annotationManager, documentViewer } = instance.Core;

    approveBtn.addEventListener('click', async () => {
      console.log("[PDFJS] 🚀 Approve clicked — saving PDF");

      try {
        const { annotationManager, documentViewer } = instance.Core;

        if (!documentViewer.getDocument()) {
          console.error("[PDFJS] ❌ No document loaded.");
          return;
        }

        // 🔁 Export annotations, then explicitly flatten them
        const xfdfData = await annotationManager.exportAnnotations();
        await annotationManager.importAnnotations(xfdfData); // Ensure annotations are properly recognized

        // 📦 Generate final PDF ensuring everything is embedded
        const arrayBuffer = await documentViewer.getDocument().getFileData({
          includeAnnotations: true, // This now works correctly after flattening
          flatten: true
        });

        const blob = new Blob([arrayBuffer], { type: 'application/pdf' });
        const formData = new FormData();
        formData.append('file', blob, 'approved.pdf');

        const response = await fetch('/api/pdf/upload', {
          method: 'POST',
          body: formData
        });

        if (response.ok) {
          alert("✅ PDF uploaded with embedded annotations.");
        } else {
          const err = await response.text();
          console.error("[PDFJS] ❌ Upload failed:", err);
          alert("Upload failed: " + err);
        }

      } catch (err) {
        console.error("[PDFJS] ❌ Unexpected error:", err);
        alert("Unexpected error during save.");
      }
    });

Hello shashikanth.n,

You have to use the merge API to merge XFDF into a PDF.

Best regards,
Tyler