---
title: "Save & download PDF locally from JavaScript viewer | Nutrient"
canonical_url: "https://www.nutrient.io/guides/web/save-a-document/to-local-storage/"
md_url: "https://www.nutrient.io/guides/web/save-a-document/to-local-storage.md"
last_updated: "2026-06-09T10:38:40.981Z"
description: "Learn how to save open documents locally using Nutrient Web SDK with a customizable download button for seamless PDF exports."
---

# Save PDFs to local storage using JavaScript

Nutrient Web SDK makes it possible to save an open document locally without a server.

This can be done programmatically by exporting the document to an `ArrayBuffer` via [`Instance#exportPDF()`] and triggering a download.

For example, here you’ll [customize the toolbar](https://www.nutrient.io/guides/web/customizing-the-interface/customizing-the-toolbar.md) to [add a download button](https://www.nutrient.io/guides/web/knowledge-base/download-exported-document.md#q-how-can-trigger-the-download-of-an-exported-document) to Nutrient Web SDK ([try it in the Playground](https://www.nutrient.io/demo/sandbox?p=eyJ2IjoxLCJzZXR0aW5ncyI6eyJmaWxlTmFtZSI6ImJhc2ljLnBkZiJ9LCJqcyI6ImNvbnNvbGUubG9nKFwiQ3VzdG9taXppbmcgdG9vbGJhciB3aXRoIGRvd25sb2FkIGJ1dHRvbi4uLlwiKTtcblxubGV0IGluc3RhbmNlO1xuXG5jb25zdCBkb3dubG9hZEJ1dHRvbiA9IHtcbiAgdHlwZTogXCJjdXN0b21cIixcbiAgaWQ6IFwiZG93bmxvYWQtZmxhdHRlbmVkXCIsXG4gIHRpdGxlOiBcIkRvd25sb2FkIHdpdGggRmxhdHRlbmVkIEFubm90YXRpb25zXCIsXG4gIGljb246ICc8c3ZnIHdpZHRoPVwiMjRcIiBoZWlnaHQ9XCIyNFwiIHZpZXdCb3g9XCIwIDAgMjQgMjRcIiBmaWxsPVwibm9uZVwiIHhtbG5zPVwiaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmdcIj48cGF0aCBkPVwiTTEyIDN2MTJtMCAwbC00LTRtNCA0bDQtNE01IDIxaDE0XCIgc3Ryb2tlPVwiY3VycmVudENvbG9yXCIgc3Ryb2tlLXdpZHRoPVwiMlwiIH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Bhbm5vdGF0aW9ucyBwYXJ0IG9mIHRoZSBwYWdlIGNvbnRlbnRcIik7XG4gICAgfSk7XG4gIH1cbn07XG5cbi8vIEdldCBkZWZhdWx0IHRvb2xiYXIgaXRlbXMgYW5kIHJlbW92ZSB0aGUgZXhpc3RpbmcgZXhwb3J0IGJ1dHRvblxuY29uc3QgaXRlbXMgPSBOdXRyaWVudFZpZXdlci5kZWZhdWx0VG9vbGJhckl0ZW1zLmZpbHRlcihcbiAgaXRlbSA9PiBpdGVtLnR5cGUgIT09IFwiZXhwb3J0LXBkZlwiXG4pO1xuXG4vLyBBZGQgb3VyIGN1c3RvbSBkb3dubG9hZCBidXR0b25cbml0ZW1zLnB1c2goZG93bmxvYWRCdXR0b24pO1xuXG5OdXRyaWVudFZpZXdlci5sb2FkKHtcbiAgLi4uYmFzZU9wdGlvbnMsXG4gIHRvb2xiYXJJdGVtczogaXRlbXNcbn0pLnRoZW4oKF9pbnN0YW5jZSkgPT4ge1xuICBpbnN0YW5jZSA9IF9pbnN0YW5jZTtcbiAgY29uc29sZS5sb2coXCJOdXRyaWVudCBsb2FkZWQhXCIpO1xuICBjb25zb2xlLmxvZyhcIkN1c3RvbSBkb3dubG9hZCBidXR0b24gYWRkZWQgKHJlcGxhY2VzIGRlZmF1bHQgRXhwb3J0IGJ1dHRvbilcIik7XG4gIGNvbnNvbGUubG9nKFwiVGhpcyB2ZXJzaW9uIGRvd25sb2FkcyB3aXRoIGZsYXR0ZW5lZCBhbm5vdGF0aW9uc1wiKTtcbn0pO1xuIiwiY3NzIjoiLyogQWRkIHlvdXIgQ1NTIGhlcmUgKi9cblx0In0%253D)):

```js

let instance;
const downloadButton = {
  type: "custom",
  id: "download-pdf",
  icon: "/download.svg",
  title: "Download",
  onPress: () => {
    instance.exportPDF().then((buffer) => {
        const blob = new Blob([buffer], { type: "application/pdf" });
        const fileName = "document.pdf";
        // Legacy IE11 support — remove if IE11 is not required.
        if (window.navigator.msSaveOrOpenBlob) {
          window.navigator.msSaveOrOpenBlob(blob, fileName);
        } else {
          const objectUrl = URL.createObjectURL(blob);
          const a = document.createElement("a");
          a.href = objectUrl;
          a.style = "display: none";
          a.download = fileName;
          document.body.appendChild(a);
          a.click();
          URL.revokeObjectURL(objectUrl);
          document.body.removeChild(a);
        }
      }).catch((error) => {
        console.error("Failed to export PDF:", error.message);
      });
  }
};

const items = NutrientViewer.defaultToolbarItems;
// Add the download button to the toolbar.
items.push(downloadButton);

NutrientViewer.load({
  toolbarItems: items
}).then((_instance) => {
    instance = _instance;
  }).catch((error) => {
    console.error("Failed to load document:", error.message);
  });

```

When exporting a document, you have several options. Refer to our guides on [flattening annotations](https://www.nutrient.io/guides/web/annotations/flatten.md) and [incremental saving](https://www.nutrient.io/guides/web/features/document-processing.md) for more details.

Auto saving can be configured for different scenarios and use cases. You can find more information in our [auto save](https://www.nutrient.io/guides/web/features/saving.md) guide.
---

## Related pages

- [Auto-saving PDF changes in our JavaScript viewer](/guides/web/features/saving.md)
- [Detecting unsaved changes in PDFs](/guides/web/save-a-document/detect-unsaved-changes.md)
- [Enable incremental saving of PDFs using JavaScript](/guides/web/features/document-processing.md)
- [Save PDF files using JavaScript](/guides/web/save-a-document.md)
- [Save PDFs to an ArrayBuffer using JavaScript](/guides/web/save-a-document/to-arraybuffer.md)
- [Save documents as PDFs on the web](/guides/web/save-a-document/save-as.md)
- [Save PDFs to Document Engine using JavaScript](/guides/web/save-a-document/to-document-engine.md)
- [Save PDFs to a remote server using JavaScript](/guides/web/save-a-document/to-remote-server.md)
- [Save PDF without annotations using JavaScript](/guides/web/save-a-document/without-annotations.md)

