API Reference

Props & Ref Methods

Complete reference for DocxEditor props and imperative ref methods — extracted from source code.

The DocxEditor component accepts the following props, grouped by concern.

Source: DocxEditorProps

Document Input

Pass your document data to the editor. Use documentBuffer for raw file data (most common), or document if you've already parsed it.

PropTypeDefaultDescription
documentBufferDocxInput | nullDocument data — ArrayBuffer, Uint8Array, Blob, or File
documentDocument | nullPre-parsed document (alternative to documentBuffer)
<DocxEditor documentBuffer={arrayBuffer} />
 
{/* Or from a File input */}
const file = e.target.files[0];
<DocxEditor documentBuffer={file} />

Editor Mode

Control how the editor behaves — direct editing, tracked suggestions, view-only, or fully read-only. Toggle between modes below to see the difference.

PropTypeDefaultDescription
modeEditorMode'editing'Editor mode: 'editing' (direct edits), 'suggesting' (track changes), or 'viewing' (read-only).
onModeChange(mode: EditorMode) => voidCallback when the editing mode changes
readOnlybooleanWhether the editor is read-only. When true, hides toolbar and rulers
{/* Google Docs-style mode switching */}
<DocxEditor
  documentBuffer={buf}
  mode="suggesting"
  onModeChange={(m) => setMode(m)}
/>
 
{/* Read-only document viewer (no toolbar, no caret) */}
<DocxEditor documentBuffer={buf} readOnly />

Toolbar & UI Controls

Toggle editor chrome — toolbar, zoom slider, rulers, margin guides, outline sidebar, and print button. Try the checkboxes below to see each prop in action.

PropTypeDefaultDescription
showToolbarbooleantrueWhether to show toolbar
showZoomControlbooleantrueWhether to show zoom control
showRulerbooleanfalseWhether to show horizontal ruler
rulerUnit'inch' | 'cm''inch'Unit for ruler display
showMarginGuidesbooleanfalseWhether to show page margin guides/boundaries
marginGuideColorstring'#c0c0c0'Color for margin guides
showOutlinebooleanfalseWhether to show the document outline sidebar
showPrintButtonbooleantrueWhether to show print button in toolbar
initialZoomnumber1.0Initial zoom level
<DocxEditor
  documentBuffer={buf}
  showToolbar
  showRuler
  rulerUnit="cm"
  showMarginGuides
  showOutline
  initialZoom={0.75}
/>

Title Bar Customization

The title bar sits above the toolbar. Add your app logo, show the document name, and place custom actions on the right. Toggle the checkboxes to see each render prop.

PropTypeDefaultDescription
renderLogo() => ReactNodeCustom logo/icon for the title bar
documentNamestringDocument name shown in the title bar
onDocumentNameChange(name: string) => voidCallback when document name changes
documentNameEditablebooleantrueWhether the document name is editable
renderTitleBarRight() => ReactNodeCustom right-side actions for the title bar
toolbarExtraReactNodeCustom toolbar actions
<DocxEditor
  documentBuffer={buf}
  renderLogo={() => <img src="/logo.svg" alt="Logo" />}
  documentName="Quarterly Report"
  onDocumentNameChange={(name) => save(name)}
  renderTitleBarRight={() => (
    <button onClick={share}>Share</button>
  )}
/>

Callbacks

React to editor events — document changes, saves, selection updates, clipboard actions, and more.

PropTypeDefaultDescription
onChange(document: Document) => voidCallback when document changes
onSave(buffer: ArrayBuffer) => voidCallback when document is saved
onSelectionChange(state: SelectionState | null) => voidCallback when selection changes
onError(error: Error) => voidCallback on error
onFontsLoaded() => voidCallback when fonts are loaded
onPrint() => voidCallback when print is triggered
onCopy() => voidCallback when content is copied
onCut() => voidCallback when content is cut
onPaste() => voidCallback when content is pasted
<DocxEditor
  documentBuffer={buf}
  onSave={(buffer) => uploadToServer(buffer)}
  onChange={(doc) => setDirty(true)}
  onError={(err) => toast.error(err.message)}
/>

Theming & Styling

Apply a custom theme, add CSS classes, or pass inline styles to the editor container.

PropTypeDefaultDescription
themeTheme | nullTheme for styling
authorstringAuthor name used for comments and track changes
classNamestringAdditional CSS class name
styleCSSPropertiesAdditional inline styles
placeholderReactNodePlaceholder when no document
loadingIndicatorReactNodeLoading indicator
printOptionsPrintOptionsPrint options for print preview
<DocxEditor
  documentBuffer={buf}
  author="Jane Smith"
  className="rounded-lg"
  placeholder={<EmptyState />}
  loadingIndicator={<Spinner />}
/>

Ref Methods

Access imperative methods via a ref. These let you programmatically save, zoom, navigate, and print.

MethodSignatureDescription
getAgent() => DocumentAgent | nullGet the DocumentAgent for programmatic access
getDocument() => Document | nullGet the current document
getEditorRef() => PagedEditorRef | nullGet the editor ref
save(options?: { selective?: boolean }) => Promise<ArrayBuffer | null>Save the document to buffer. Pass { selective: false } to force full repack.
setZoom(zoom: number) => voidSet zoom level
getZoom() => numberGet current zoom level
focus() => voidFocus the editor
getCurrentPage() => numberGet current page number
getTotalPages() => numberGet total page count
scrollToPage(pageNumber: number) => voidScroll to a specific page
openPrintPreview() => voidOpen print preview
print() => voidPrint the document directly
const ref = useRef<DocxEditorRef>(null);
 
// Save and upload
const buffer = await ref.current.save();
await fetch('/api/upload', { method: 'POST', body: buffer });
 
// Navigation & zoom
ref.current.setZoom(1.5);
ref.current.scrollToPage(3);
 
// Get document model
const doc = ref.current.getDocument();
console.log(doc.body.sections.length);
 
// Print
ref.current.print();