Save PDFs to Document Engine using JavaScript
When using Nutrient Web SDK in server-backed operational mode, saving a document to the Document Engine backend is easy. Depending on the autoSaveMode set, it can be done automatically with NutrientViewer.AutoSaveMode#IMMEDIATE and NutrientViewer.AutoSaveMode#INTELLIGENT, or programmatically on demand by setting NutrientViewer.AutoSaveMode#DISABLED and calling instance.save when required.
The following example shows how to set the configuration object so that saving is performed automatically:
NutrientViewer.load({ ...otherOptions, autoSaveMode: NutrientViewer.AutoSaveMode.IMMEDIATE}).catch((error) => { console.error("Failed to load document:", error.message);});With autosave disabled, call instance.save when you need to persist changes.
In Nutrient Web SDK 1.24.0 and later, instance.applyOperations() and Document Editor Save persist pending changes to Document Engine before applying operations. Disabling autosave doesn’t prevent these saves.
The following example saves when annotations are created:
NutrientViewer.load({ ...otherOptions, autoSaveMode: NutrientViewer.AutoSaveMode.DISABLED}) .then((instance) => { instance.addEventListener("annotations.create", (annotations) => { console.log("annotations created:", annotations.toJS()); // Save changes when new annotations are created. instance.save(); }); }) .catch((error) => { console.error("Failed to load document:", error.message); });When you export a document, you can choose how Nutrient Web SDK writes the output. For more information, refer to the flattening annotations guide and the incremental saving guide.
Use autosave to configure when Nutrient Web SDK saves changes. For more information, refer to the autosave guide.
Call instance.save() before exporting if autosave is disabled, or after an undo, redo, or paste. Otherwise, the exported file doesn’t include unsaved annotations.