Skip to content
Document Authoring DA  API Docs v1.18.0
npmGitHub

DocAuthDocumentInput

DocAuthDocumentInput:

type DocAuthDocumentInput =
| Blob

A string, Uint8Array, or ArrayBuffer will be treated as a UTF-8 encoded document authoring document in JSON format and loaded. An object will be treated as a JavaScript representation of a Document Authoring document (e.g. the result of JSON.parse on a Document Authoring JSON string). In Node.js, Buffer extends Uint8Array, so a Buffer returned by fs.readFile can be passed directly.

// Load from JSON
const docString = '{"version":"7.0","content":[...]}';
const docFromString = await system.loadDocument(docString);
// Load from a JavaScript object
const docObject = { version: '7.0', content: [...] };
const docFromObject = await system.loadDocument(docObject);
// Load from UTF-8 bytes
const bytes = new TextEncoder().encode('{"version":"7.0","content":[...]}');
const docFromBytes = await system.loadDocument(bytes);
// Load from a Node Buffer
const docBytes = await fs.promises.readFile('document.docjson');
const docFromBuffer = await system.loadDocument(docBytes);
// Load from a Blob (e.g. from a file input)
const fileInput = document.querySelector('input[type="file"]');
const blob = fileInput.files[0];
const docFromBlob = await system.loadDocument(blob);
// Load from a fetch Response
const response = await fetch('/api/document.json');
const docFromResponse = await system.loadDocument(response);
// Load from a Promise (fetch is automatically awaited)
const docFromPromise = await system.loadDocument(fetch('/api/document.json'));
// Load from a Promise that resolves to a Blob
const blobPromise = fetch('/api/document.json').then((r) => r.blob());
const docFromBlobPromise = await system.loadDocument(blobPromise);