Download an exported PDF document | Nutrient
Use NutrientViewer.Instance#exportPDF() to export a document as an ArrayBuffer. Then create an object URL and assign it to an anchor element to start the download.
If autosave is disabled, call instance.save() before exporting. Otherwise, the downloaded file doesn’t include unsaved annotations.
The following example exports a PDF and starts a browser download:
const buffer = await instance.exportPDF();const supportsDownloadAttribute = HTMLAnchorElement.prototype.hasOwnProperty( "download");const blob = new Blob([buffer], { type: "application/pdf" });if (navigator.msSaveOrOpenBlob) { navigator.msSaveOrOpenBlob(blob, "download.pdf");} else if (!supportsDownloadAttribute) { const reader = new FileReader(); reader.onloadend = function () { const dataUrl = reader.result; downloadPdf(dataUrl); }; reader.readAsDataURL(blob);} else { const objectUrl = window.URL.createObjectURL(blob); downloadPdf(objectUrl); window.URL.revokeObjectURL(objectUrl);}function downloadPdf(blob) { const a = document.createElement("a"); a.href = blob; a.style.display = "none"; a.download = "download.pdf"; a.setAttribute("download", "download.pdf"); document.body.appendChild(a); a.click(); document.body.removeChild(a);}This example was tested with Nutrient Web SDK 2020.5.1.