Save PDF files using JavaScript
Nutrient Web SDK includes support for client-side PDF saving using JavaScript (without a server). Edited or newly created PDFs can be saved to an ArrayBuffer, to a remote server, or to local storage.
Quick start
Export any open PDF to an ArrayBuffer with a single API call:
// Get the PDF as an `ArrayBuffer`.const buffer = await instance.exportPDF();Download to local file
Trigger a browser download from the exported buffer:
// Export and download the PDF.const buffer = await instance.exportPDF();const blob = new Blob([buffer], { type: "application/pdf" });const url = URL.createObjectURL(blob);
const a = document.createElement("a");a.href = url;a.download = "document.pdf";document.body.appendChild(a);a.click();
URL.revokeObjectURL(url);document.body.removeChild(a);Send to a server
Post the exported PDF to your backend:
const buffer = await instance.exportPDF();
await fetch("/api/documents", { method: "POST", headers: { "Content-Type": "application/pdf" }, body: buffer,});Add a download button to the toolbar
Combine saving with UI customization:
let instance;
const downloadButton = { type: "custom", id: "download-pdf", icon: "/icons/download.svg", title: "Download", onPress: async () => { const buffer = await instance.exportPDF(); const blob = new Blob([buffer], { type: "application/pdf" }); const url = URL.createObjectURL(blob);
const a = document.createElement("a"); a.href = url; a.download = "document.pdf"; a.click();
URL.revokeObjectURL(url); },};
const toolbarItems = NutrientViewer.defaultToolbarItems;toolbarItems.push(downloadButton);
instance = await NutrientViewer.load({ container: "#viewer", document: "/path/to/document.pdf", toolbarItems,});Key capabilities
- Local storage or remote URL — Save PDF files to any location
- Incremental save — Improve performance when saving large PDFs
- Auto save — Automatically save edits to the file
- Client-side — Save PDFs directly in the browser (no server needed)
- Headless — Edited or newly created files can be saved without a UI
- Extendable — Add annotation, signing, editing, forms, and more
Guides for saving a document
Save a document to local storage
How to save a document to local storage
Save a document to an ArrayBuffer
How to save a document to an ArrayBuffer
Save a document to a remote server
How to save a document to a remote server
Save a document to Document Engine
How to save a document to Document Engine
Incremental saving
How to append changes to the end of a PDF, instead of rewriting
Auto-save
How to configure the way changes are automatically saved
Save as
How to save a document as a new file
Detect unsaved changes
How to check for unsaved changes and register state change listeners
Start your free trial for unlimited access and expert support.