Use additional import and export formats
Before you start, ensure the Document Authoring library is installed and running. Refer to the getting started guide.
Document Authoring provides generic import and export APIs that work across DOCX, PDF, DocJSON, and additional formats such as RTF, ODT, Markdown, plain text, and supported image types.
Supported formats
Use DocAuthSystem.import() to import these formats:
docxdotxdocmrtfodtmarkdowntxtdocjsonpngjpegbmpgifwebp
Use DocAuthDocument.export() to export these formats:
pdfdocxmarkdownrtfodt
The example code omits error handling. Add it before using this code in production.
Import a document with automatic format detection
Use DocAuthSystem.import() to import a document and let Document Authoring detect the format from the file content and optional file name:
const fileInput = document.querySelector('input[type="file"]');
fileInput.addEventListener('change', async () => { const file = fileInput.files?.[0]; if (!file) { return; }
const importedDocument = await docAuthSystem.import(file, { fileName: file.name, });
const editor = await docAuthSystem.createEditor( document.getElementById('editor'), { document: importedDocument }, );});Import a document with an explicit format
If you already know the format, pass it in the import configuration to skip auto-detection:
const response = await fetch('/content/guide.md');
const document = await docAuthSystem.import(response, { format: 'markdown',});This is useful when you import data from a source where the extension or MIME type isn’t reliable.
Export to Markdown, RTF, or ODT
Use DocAuthDocument.export() with a format-specific configuration:
const currentDoc = editor.currentDocument();
const markdown = await currentDoc.export({ format: 'markdown' });const rtf = await currentDoc.export({ format: 'rtf' });const odt = await currentDoc.export({ format: 'odt' });Each call returns an ArrayBuffer containing the exported file data.
Create a document from plain text
If your source content is plain text rather than an existing file, use DocAuthSystem.createDocumentFromPlaintext():
const text = `First paragraph
Second paragraph with a line break\nand continuation.`;
const textDocument = await docAuthSystem.createDocumentFromPlaintext(text, { pageSize: 'A4',});
const editor = await docAuthSystem.createEditor( document.getElementById('editor'), { document: textDocument },);This method interprets:
\nas a line break inside a paragraph\n\nas a paragraph break\tas spaces
Use abort signals for long-running imports or exports
The generic import and export APIs accept an optional AbortSignal:
const controller = new AbortController();
const document = await docAuthSystem.import(fetch('/documents/template.odt'), { fileName: 'template.odt', abortSignal: controller.signal,});
const exported = await editor.currentDocument().export({ format: 'markdown', abortSignal: controller.signal,});