# Annotations not saving to the pdf

**URL:** <https://pdfjs.community/t/annotations-not-saving-to-the-pdf/3712>\
**Category:** Technical Support\
**Tags:** pdfjs-express\
**Created:** [June 1, 2025, 9:46am UTC](https://pdfjs.community/t/annotations-not-saving-to-the-pdf/3712 "2025-06-01T09:46:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shashikanth.n](https://avatars.discourse-cdn.com/v4/letter/s/a9a28c/32.png) [@shashikanth.n](https://pdfjs.community/u/shashikanth.n)\
**Post date:** [June 1, 2025, 9:46am UTC](https://pdfjs.community/t/annotations-not-saving-to-the-pdf/3712/1 "2025-06-01T09:46:25Z")

</div>

**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.");
      }
    });

```

---

<div class="post-metadata">

**Author:** ![tgordon](https://avatars.discourse-cdn.com/v4/letter/t/aca169/32.png) [@tgordon](https://pdfjs.community/u/tgordon)\
**Post date:** [June 2, 2025, 2:51pm UTC](https://pdfjs.community/t/annotations-not-saving-to-the-pdf/3712/3 "2025-06-02T14:51:53Z")

</div>

Hello shashikanth.n,

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

> **[Merging XFDF using the Express REST API | Documentation](https://pdfjs.express/documentation/utils/merge)**

Best regards,  
Tyler
