Advanced drawing rendering
Render charts, DrawingML diagram layout, drawing effects, VML text paths, and EMF and WMF pictures with the drawing module.
The drawing module renders charts, DrawingML diagram layout, drawing effects, VML text paths, and EMF and WMF pictures in the editor and in PDF export. It requires the EigenPal Pro License. Import it from @docx-editor.dev/pro/drawing.
Register the drawing module
Pass drawingModule() to the editor through modules:
import { DocxEditor } from '@docx-editor.dev/react';
import { drawingModule } from '@docx-editor.dev/pro/drawing';
// Next.js; with Vite, read import.meta.env.VITE_DOCX_LICENSE.
const licenseKey = process.env.NEXT_PUBLIC_DOCX_LICENSE;
const modules = [drawingModule({ licenseKey })];
export function Editor({ bytes }: { bytes: Uint8Array }) {
return (
<DocxEditor.Root document={bytes} modules={modules}>
<DocxEditor.Toolbar />
<DocxEditor.Viewport>
<DocxEditor.Content />
</DocxEditor.Viewport>
</DocxEditor.Root>
);
}<script setup lang="ts">
import {
DocxEditorContent,
DocxEditorRoot,
DocxEditorToolbar,
DocxEditorViewport,
} from '@docx-editor.dev/vue';
import { drawingModule } from '@docx-editor.dev/pro/drawing';
defineProps<{ bytes: Uint8Array }>();
const licenseKey = import.meta.env.VITE_DOCX_LICENSE;
const modules = [drawingModule({ licenseKey })];
</script>
<template>
<DocxEditorRoot :document="bytes" :modules="modules">
<DocxEditorToolbar />
<DocxEditorViewport>
<DocxEditorContent />
</DocxEditorViewport>
</DocxEditorRoot>
</template>reviewModule()also installs the drawing renderers. Registering both is harmless.- Installation applies to the whole page or process and persists after editor disposal.
- Register before the first document opens. Open documents keep their projections until you reopen them or remount the editor.
What renders
Core renders shapes, pictures, groups, text boxes, and saved DrawingML diagram drawings without this module. The module adds:
| Drawing | With the module | Without the module |
|---|---|---|
| Classic and extended charts (waterfall, funnel, histogram, Pareto, box and whisker) | From the values cached in the chart part. Classic charts are editable; see Charts | Saved fallback picture or drawing, or a labeled placeholder |
| DrawingML diagram saved without its drawing | Laid out from its data, layout, style, and color parts | Labeled placeholder |
| Glow, inner shadow, reflection, soft edge, and dark-edged bevel rim | Painted on shapes, lines, and pictures | Shape or picture paints without the effect |
| VML text paths | Text fitted to the shape, guides, or an arch | Inline: placeholder. Floating: not rendered |
| EMF and WMF pictures | Vector paths, text, and bitmaps in PDF export | Rasterized |
Charts use cached values only. The editor never refreshes them from an embedded workbook or external data. Data edits update cached values and supported embedded workbooks. Unsupported workbooks retain their original values. For per-chart support, see DOCX feature support.
Use the module without an editor
For headless conversion, call installDrawing() once at startup, before you open any document:
import { installDrawing } from '@docx-editor.dev/pro/drawing';
installDrawing({ licenseKey: process.env.DOCX_LICENSE });| Package | Drawing setup |
|---|---|
@docx-editor.dev/docx-to-pdf | Installs the renderers automatically. No registration needed. |
@docx-editor.dev/editor-api | Add @docx-editor.dev/pro as a dependency and call installDrawing() first. |
@docx-editor.dev/docx-to-markdown | Add @docx-editor.dev/pro as a dependency and call installDrawing() first. |
PDF export reports a drawing diagnostic for a drawing that cannot render, and the default strict policy rejects that export. For the best-effort policy, see PDF diagnostics.
Replace a placeholder
Register a DocxEditor.UnsupportedElement declaration to replace a placeholder, with or without the module. This example shows the chart title or its alternative text:
import { DocxEditor, type UnsupportedElement } from '@docx-editor.dev/react';
const isChartPlaceholder = (element: UnsupportedElement) =>
element.drawing?.placeholderGraphicKind === 'chart';
const chartLabel = ({ drawing }: UnsupportedElement) =>
drawing?.chart?.title ?? drawing?.accessibility.label ?? 'Chart';
export function Editor({ bytes }: { bytes: Uint8Array }) {
return (
<DocxEditor document={bytes}>
<DocxEditor.UnsupportedElement match={isChartPlaceholder}>
{({ element }) => <div className="chart">{chartLabel(element)}</div>}
</DocxEditor.UnsupportedElement>
</DocxEditor>
);
}<script setup lang="ts">
import { DocxEditor, type UnsupportedElement } from '@docx-editor.dev/vue';
defineProps<{ bytes: Uint8Array }>();
const isChartPlaceholder = (element: UnsupportedElement) =>
element.drawing?.placeholderGraphicKind === 'chart';
const chartLabel = ({ drawing }: UnsupportedElement) =>
drawing?.chart?.title ?? drawing?.accessibility.label ?? 'Chart';
</script>
<template>
<DocxEditor :document="bytes">
<DocxEditor.UnsupportedElement :match="isChartPlaceholder">
<template #default="{ element }">
<div class="chart">
{{ chartLabel(element) }}
</div>
</template>
</DocxEditor.UnsupportedElement>
</DocxEditor>
</template>The title and alternative text come from the document. Render them as text, never as HTML.
- Declarations receive placeholders by default. Set
includePartialto also receive partially rendered drawings and saved fallbacks. For more information, see Replace a partially rendered drawing. - Your component fills the drawing's box. It changes the editor display only, not the saved drawing or PDF output.
Match on drawing.placeholderGraphicKind:
| Value | Content |
|---|---|
chart | Chart |
diagram | DrawingML diagram |
textbox | DrawingML shape, with or without text |
group | Shape group |
canvas | Drawing canvas |
shape | Legacy VML drawing, such as a VML text path |
graphic | Other graphic |
null | Picture that cannot render, such as an EMF, WMF, or TIFF picture that fails conversion |
For more options, see Custom unsupported-content components.
Inspect chart metadata
A drawing that holds a readable chart part carries drawing.chart. This example lists every chart with its page number, state, and title:
import { openDocumentForExport } from '@docx-editor.dev/core/export';
import { forEachSemanticDrawing } from '@docx-editor.dev/core/layout';
import { installDrawing } from '@docx-editor.dev/pro/drawing';
installDrawing({ licenseKey: process.env.DOCX_LICENSE });
const opened = openDocumentForExport(bytes);
if (!opened.ok) throw new Error(opened.reason);
try {
const layout = await opened.session.layout();
forEachSemanticDrawing(layout, ({ drawing, page }) => {
const chart = drawing.chart;
if (chart) console.log(page.index + 1, chart.shownAs, chart.title);
});
} finally {
opened.session.dispose();
}Without an EigenPal Pro License, leave out installDrawing(); charts then report fallback or placeholder. A header or footer chart appears once per page.
| Property | Meaning |
|---|---|
title | Plain-text title, whitespace collapsed, at most 200 UTF-16 code units. null when no readable title exists. |
plotTypes | Plot types in document order, at most 8 entries, such as ['bar', 'line']. |
shownAs | chart (module draws it), fallback (saved fallback shows), or placeholder. |
drawing.chartis absent when the chart part is missing or damaged.shownAsfollows the renderers installed at open.- Classic plot types:
area,area3D,bar,bar3D,bubble,doughnut,line,line3D,ofPie,pie,pie3D,radar,scatter,stock,surface,surface3D. - Extended plot types:
waterfall,funnel,histogram,pareto,boxWhisker,treemap,sunburst,regionMap, or[]for an unknown type. - Extended charts read explicit title text only. Classic charts can also use cached cell text or a single series name.
Import DrawingChartSummary, DrawingChartShownAs, DrawingChartPlotType, and DrawingPlaceholderKind from @docx-editor.dev/core/layout.
Handle chart edits
The editor treats a chart and its fallback as one read-only object with no authoring controls.
- Delete, Backspace, the delete image command, or a range that includes the chart removes both in one undo step, or one tracked deletion.
- Picture commands, such as resize, crop, wrap, and alternative text, are refused with a localized reason.
- Copy, cut, and rich paste of content that holds a chart are refused. A refused cut deletes nothing.
- Selection locks block deletion in every rendering state.
The refused picture edit has a different code in each layer:
| Layer | Code |
|---|---|
Editor commands (editor.can() and editor.exec()) | unsupported, with the chart reason as reason |
| Document store transactions | The rejection chart-drawing |
@docx-editor.dev/editor-api automation | The diagnostic edit.unsupported-content in error.debugInfo.innerError.code, not error.code |
The rule reads only the document, so collaborating editors decide the same way with or without the module.
Check export limits
The editor and PDF export pick what to show for a chart in this order:
- If the module renders the chart, they show the chart.
- If a saved fallback picture or drawing renders, they show it. A fallback produces no PDF diagnostic and can differ from the cached values.
- Otherwise, the editor shows a labeled placeholder at the fallback's size. PDF export leaves the chart out with a
drawingdiagnostic.
- A drawn chart never reads its fallback picture, so a slow or broken fallback cannot delay the editor or PDF export.
- Markdown export uses each visible chart's fallback picture. If it does not load within the resource timeout, the export leaves the chart out with a warning.
- Saving preserves chart markup, related parts, and fallback content. A hidden chart stays hidden.
Limits
- Pie or radar combination charts, surface charts over 20,000 points, and invalid chart caches do not render.
- DrawingML diagrams with picture fills, and VML text paths with nonvertical gradients or perspective extrusion, do not render.
- Registering the module does not recalculate a saved DrawingML diagram drawing.