This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/document-authoring/working-with-documents/export.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Export documents

Use DocAuthDocument.export() to export the document currently shown in an editor. Pass the target format in the export configuration. The method returns an ArrayBuffer with the file bytes, which you can download, upload, or store.

Before you start, make sure the Document Authoring library is installed and running in your app. If you haven’t set it up yet, refer to the getting started guide.

The examples omit error handling. Add it before you use this code in production.

Supported formats

DocAuthDocument.export() writes these formats:

  • pdf — PDF, including PDF/A.
  • docx — Microsoft Word.
  • markdown — Markdown.
  • rtf — Rich Text Format.
  • odt — OpenDocument Text.

Get the document from the editor with currentDocument() before you export it:

const currentDoc = editor.currentDocument();

Export to PDF

Pass format: 'pdf' to export the document as a PDF:

const pdf = await currentDoc.export({ format: 'pdf' });

For long-term archiving, set PDF_A to produce a PDF/A-compliant file:

const pdfa = await currentDoc.export({ format: 'pdf', PDF_A: true });

Export to DOCX

Pass format: 'docx' to export the document as a DOCX file:

const docx = await currentDoc.export({ format: 'docx' });

DOCX export is best effort, so use it for finalized documents. For everyday saving, store DocJSON instead. For more information, refer to the DocJSON guide.

Export to Markdown, RTF, or ODT

Pass the target format to export Markdown, RTF, or ODT:

const markdown = await currentDoc.export({ format: 'markdown' });
const rtf = await currentDoc.export({ format: 'rtf' });
const odt = await currentDoc.export({ format: 'odt' });

Download an exported file

export() returns raw bytes, not a download. To save the result on the user’s device, wrap the bytes in a Blob, create an object URL, and click a temporary link:

const pdf = await currentDoc.export({ format: 'pdf' });
const url = URL.createObjectURL(new Blob([pdf], { type: 'application/pdf' }));
const link = document.createElement('a');
link.href = url;
link.download = 'document.pdf';
link.click();
URL.revokeObjectURL(url);

Cancel a long export

Pass an AbortSignal to cancel an export in progress:

const controller = new AbortController();
const markdown = await currentDoc.export({
format: 'markdown',
abortSignal: controller.signal,
});
// `controller.abort()` cancels the export.

Learn more

Import documents
Open DOCX, PDF, RTF, ODT, Markdown, and image files.

DocJSON
Load and save Document Authoring’s native format.

Programmatic editing
Read and change a document from code.