Customizing download/export buttons in our JavaScript PDF viewer
The built-in download button can be activated using instance.setToolbarItems():
For review and commenting workflows, keep Save review and Export PDF as separate actions. Use instance.exportInstantJSON() to persist the editable review layer, and use instance.exportPDF() only when users need a final PDF output. Refer to the keyboard-accessible review workflow guide for an implementation pattern.
The following example adds the built-in export button to the main toolbar:
instance.setToolbarItems((items) => items.concat([{ type: "export-pdf" }]));Or, if you prefer, you can also set it in the NutrientViewer.Configuration object passed to NutrientViewer.load():
NutrientViewer.load({ toolbarItems: NutrientViewer.defaultToolbarItems.concat([ { type: "export-pdf" } ])});If you need more fine-grained control over the download operation, with instance.exportPDF() and the possibility of customizing the toolbar, you can easily add your own download button to Nutrient Web SDK:
const downloadButton = { type: "custom", id: "download-pdf", icon: "/download.svg", title: "Download", onPress: () => { pspdfkitInstance.exportPDF().then((buffer) => { const blob = new Blob([buffer], { type: "application/pdf" }); const fileName = "document.pdf"; if (window.navigator.msSaveOrOpenBlob) { window.navigator.msSaveOrOpenBlob(blob, fileName); } else { const objectUrl = window.URL.createObjectURL(blob); const a = document.createElement("a"); a.href = objectUrl; a.style = "display: none"; a.download = fileName; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(objectUrl); document.body.removeChild(a); } }); }};
NutrientViewer.load({ toolbarItems: NutrientViewer.defaultToolbarItems.concat([downloadButton])});Hiding the download button
You can remove the download button from the toolbar by getting the array of current toolbar items via instance.toolbarItems, filtering it, and setting the new array:
const items = instance.toolbarItems;// Hide the toolbar item with the type "export-pdf" by removing it from the array of items.instance.setToolbarItems( items.filter((item) => item.type !== "export-pdf"));