When you use Nutrient Web SDK with Document Engine, all of a document’s annotations are imported from Document Engine when you open it. When you create new annotations or update existing annotations through the UI or the API, the changes are exported to Document Engine as well. This process is transparent to you and your users. You can control when the annotations are saved by changing the auto-save mode.

Recommendation summary:

  • Instant JSON — Default format for internal annotation persistence and sync payloads.
  • XFDF — Use when you need interoperability with external PDF tools.
  • Server-backed (Document Engine with Instant synchronization) — Recommended for collaborative persistence and synchronization across users/devices.

If you’re deciding between these approaches, start with how to choose Instant JSON vs. XFDF vs. server-backed sync. For implementation patterns, refer to the review persistence architecture.

With Instant, changes made to annotations are automatically synchronized across all connected users, enabling real-time collaboration capabilities in your application.

Importing and exporting annotations in Instant JSON with Document Engine

You can import and export annotations (including custom rendered annotations) from and to documents opened from Document Engine in the Instant JSON format.

To import annotations in the Instant JSON format into the currently open document, use the NutrientViewer.Instance.applyOperations API, as demonstrated in the following code snippet. The instantJson variable in the code below is an Instant JSON object — for example, the result of parsing a JSON string with JSON.parse(opens in a new tab):

await instance.applyOperations([
{ type: "applyInstantJson", instantJson: instantJson }
]);

To export annotations, use the NutrientViewer.Instance.exportInstantJSON method. For example, to print an opened document’s Instant JSON to the console, use the following code snippet:

const instantJSON = await instance.exportInstantJSON();
console.log(instantJSON);

Calling NutrientViewer.Instance.applyOperations forces a document to reload. To avoid this, import annotations from Instant JSON when you upload a document to Document Engine, or any time during the document lifecycle. For more information, refer to the importing and exporting Instant JSON with Document Engine guide.

Importing and exporting annotations in XFDF with Document Engine

You can also import and export annotations (including custom rendered annotations) from and to documents opened from Document Engine in the XFDF format.

To import annotations as XFDF into the currently open document, use the NutrientViewer.Instance.applyOperations API, as demonstrated in the following code snippet. The xfdf variable in the code below is an XFDF string:

await instance.applyOperations([
{ type: "applyXfdf", xfdf: xfdf }
]);

To export annotations, use the NutrientViewer.Instance.exportXFDF method. For example, to print the opened document’s XFDF file to the console, use the following code snippet:

const xfdf = await instance.exportXFDF();
console.log(xfdf);

Calling NutrientViewer.Instance.applyOperations forces a document to reload. To avoid this, you can import annotations from XFDF when you upload a document to Document Engine, or any time during the document lifecycle. For more information, refer to the Document Engine import and export guide.