DocAuthSystem
DocAuthSystem:
{ createDocumentFromPlaintext(text: string, options?: CreateDocumentFromPlaintextOptions): Promise<DocAuthDocument>;}A DocAuthSystem instance holds the internal WASM engine and loaded fonts. It is used to load or import documents and create
DocAuthEditor instances.
Methods
Section titled “Methods”loadDocument()
Section titled “loadDocument()”loadDocument(
documentInput):Promise<DocAuthDocument>
Loads a document stored in the Document Authoring format. The document can be provided as a JSON string or a JavaScript object.
Parameters
Section titled “Parameters”documentInput
Section titled “documentInput”Returns
Section titled “Returns”Examples
Section titled “Examples”// Load from objectconst docData = { version: '7.0', content: [...] };const doc = await system.loadDocument(docData);// Load from serverconst doc = await system.loadDocument(fetch('/api/documents/123'));// Load and create editorconst doc = await system.loadDocument(savedDocJSON);const editor = await system.createEditor(targetElement, { document: doc });- DocJSON guide
DocAuthDocumentInputfor supported input types.
importDOCX()
Section titled “importDOCX()”importDOCX(
docx,options?):Promise<DocAuthDocument>
Imports a DOCX document.
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Examples
Section titled “Examples”// Import from file inputconst fileInput = document.querySelector('input[type="file"]');const file = fileInput.files[0];const doc = await system.importDOCX(file);// Import from URLconst doc = await system.importDOCX(fetch('/documents/template.docx'));// Import with abort signalconst controller = new AbortController();const doc = await system.importDOCX(file, { abortSignal: controller.signal,});// Complete workflow: import DOCX, edit, export PDFconst doc = await system.importDOCX(fetch('/template.docx'));const editor = await system.createEditor(targetElement, { document: doc });// ... user edits document ...const pdfBuffer = await editor.currentDocument().exportPDF();- DOCX import guide
BlobInputfor supported input types.
createEditor()
Section titled “createEditor()”createEditor(
target,options?):Promise<DocAuthEditor>
Creates an editor in the specified HTML element. IMPORTANT: The position of the target element cannot be static or unset. If
unsure, use relative.
Parameters
Section titled “Parameters”target
Section titled “target”options?
Section titled “options?”Returns
Section titled “Returns”Examples
Section titled “Examples”// Shared code for the examples below - ensure target element has proper positioningconst target = document.getElementById('editor');target.style.position = 'relative';target.style.height = '600px';// Create editor with empty documentconst editor = await system.createEditor(target);// Create editor with existing documentconst doc = await system.loadDocument(docJSON);const editor = await system.createEditor(target, { document: doc });// Complete workflow with event handlingconst editor = await system.createEditor(target);editor.on('content.change', async () => { const doc = await editor.currentDocument().saveDocument();});- Getting started guide
CreateEditorOptionsfor available options.
createDocumentFromPlaintext()
Section titled “createDocumentFromPlaintext()”createDocumentFromPlaintext(
text,options?):Promise<DocAuthDocument>
Creates a document from plain text by interpreting patterns and replacing characters. E.g.:
\ncreates a line break in a paragraph\n\nseparates paragraphs\tis replaced with spaces
Parameters
Section titled “Parameters”options?
Section titled “options?”CreateDocumentFromPlaintextOptions
Returns
Section titled “Returns”Examples
Section titled “Examples”// Simple text documentconst doc = await system.createDocumentFromPlaintext('Hello World');// Multi-paragraph documentconst text = `First paragraph.
Second paragraph with line break\nand continuation.`;const doc = await system.createDocumentFromPlaintext(text);// With custom page settingsconst doc = await system.createDocumentFromPlaintext('My content', { pageSize: 'A4', pageMargins: { left: 72, right: 72, top: 72, bottom: 72 },});// Create document and editor in one flowconst doc = await system.createDocumentFromPlaintext('Initial content');const editor = await system.createEditor(targetElement, { document: doc });CreateDocumentFromPlaintextOptions for available options.
destroy()
Section titled “destroy()”destroy():
void
Releases resources held by the system. IMPORTANT: The system and any editors created by this system can no longer be used after calling this.
Returns
Section titled “Returns”Example
Section titled “Example”// Clean up when doneeditor.destroy();system.destroy();
// Or use try-finally patterntry { const editor = await system.createEditor(target); // ... use editor ... editor.destroy();} finally { system.destroy();}