Rasterex APINPM Package/docs/components/annotation/import

Import Annotations

Load annotation JSON or Rasterex XML into the active document with the npm SDK.

Overview

Open the target document before importing. Await viewer.documents.open(options) so the intended document is active. The connected Canvas must support annotation import.

Allow one import at a time per viewer. Keep the active document and version fixed while the import is pending. Use stored data that already belongs to that document version.

Import JSON

Pass a native or flat annotation record, an array of records, an { items } snapshot, or JSON text containing one of those forms. Provide at least one serializable record with a valid native Type. The example accepts snapshot from host storage, such as a snapshot previously read with viewer.annotations.getData({ filter: "all" }).

Merge is the default. Existing JSON GUIDs are skipped by default. Use replacePolicy: "replace" only when you intend to replace matching JSON GUIDs. Compare the refreshed list against the expected GUIDs before reporting success.

typescript
const receipt = await viewer.annotations.load({
  format: "json",
  data: snapshot,
  mode: "merge",
  replacePolicy: "skip"
});

const { items } = await viewer.annotations.getData({ filter: "all" });
Import JSON

Import Rasterex XML

Supply markupUrl as an absolute HTTP(S) URL without embedded credentials, reachable by the deployed Canvas. The URL must serve a Rasterex markup export. URL imports are XML and merge only. Matching GUID behavior follows the native XML loader.

The SDK also accepts inline Rasterex XML. Inline requires a browser XML parser and complete native records in a RasterexMarkup export without a document type declaration. Verify inline support on the target Canvas build. The local test parent’s paste option uses a temporary local URL and is specific to that harness.

typescript
const receipt = await viewer.annotations.load({
  format: "xml",
  source: "url",
  data: markupUrl
});

const { items } = await viewer.annotations.getData({ filter: "all" });
Import Rasterex XML

Import Options

mode: "replaceAll" clears existing annotations before loading validated inline JSON or XML. Require explicit user confirmation and keep a recovery snapshot. Canvas import is not transactional, so a failure can leave partial changes.

measurementScalePolicy: "currentPage" is the default. Use "preserve" when restoring valid saved measurement calibration. A preserve request requires the Canvas reply to confirm that policy.

emitCreated defaults to true. Set it to false if the host does not want import-triggered creation callbacks. Use the import result and refreshed records to track the batch.

Result and Error Handling

LoadAnnotationsResult includes requestId, loaded, skipped, total, format, merge, replacePolicy and optional measurementScalePolicy. Counts are Canvas receipts. loaded can include a matching GUID already present before the import, so use a refreshed list to confirm the records.

The SDK generates a request ID unless you supply a new nonblank ID of at most 256 characters. timeoutMs defaults to commandTimeoutMs. A timeout leaves the outcome unknown. Inspect the active records and reconnect before attempting another import. Do not apply a late result to a different document version.