Embedding annotations in a PDF
Embedding annotations into a PDF document using Nutrient Web SDK can be done either with the UI or programmatically using the public API.
In both cases, use the API to persist annotations to the document automatically or on demand.
Persisting annotations automatically
Annotations save automatically to the document, so you don’t need to change any setting. The auto saving mechanism, enabled by default, persists new changes as they occur:
NutrientViewer.load({ autoSaveMode: NutrientViewer.AutoSaveMode.INTELLIGENT}).then((instance) => { instance.addEventListener("annotations.didSave", (annotations) => { console.log("Annotations saved!", annotations.toJS()); });});Persisting annotations on demand
If you need more control over when annotations are persisted to the document, disable auto saving and call instance.save() at the necessary moment instead:
NutrientViewer.load({ autoSaveMode: NutrientViewer.AutoSaveMode.DISABLED}).then((instance) => { instance.addEventListener("annotations.create", (annotations) => { instance.save(); });});Save annotations before exporting or printing the document to make sure all changes are included.
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.