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>
  );
}
  • 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:

DrawingWith the moduleWithout 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 ChartsSaved fallback picture or drawing, or a labeled placeholder
DrawingML diagram saved without its drawingLaid out from its data, layout, style, and color partsLabeled placeholder
Glow, inner shadow, reflection, soft edge, and dark-edged bevel rimPainted on shapes, lines, and picturesShape or picture paints without the effect
VML text pathsText fitted to the shape, guides, or an archInline: placeholder. Floating: not rendered
EMF and WMF picturesVector paths, text, and bitmaps in PDF exportRasterized

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 });
PackageDrawing setup
@docx-editor.dev/docx-to-pdfInstalls the renderers automatically. No registration needed.
@docx-editor.dev/editor-apiAdd @docx-editor.dev/pro as a dependency and call installDrawing() first.
@docx-editor.dev/docx-to-markdownAdd @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>
  );
}

The title and alternative text come from the document. Render them as text, never as HTML.

  • Declarations receive placeholders by default. Set includePartial to 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:

ValueContent
chartChart
diagramDrawingML diagram
textboxDrawingML shape, with or without text
groupShape group
canvasDrawing canvas
shapeLegacy VML drawing, such as a VML text path
graphicOther graphic
nullPicture 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.

PropertyMeaning
titlePlain-text title, whitespace collapsed, at most 200 UTF-16 code units. null when no readable title exists.
plotTypesPlot types in document order, at most 8 entries, such as ['bar', 'line'].
shownAschart (module draws it), fallback (saved fallback shows), or placeholder.
  • drawing.chart is absent when the chart part is missing or damaged. shownAs follows 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:

LayerCode
Editor commands (editor.can() and editor.exec())unsupported, with the chart reason as reason
Document store transactionsThe rejection chart-drawing
@docx-editor.dev/editor-api automationThe 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:

  1. If the module renders the chart, they show the chart.
  2. If a saved fallback picture or drawing renders, they show it. A fallback produces no PDF diagnostic and can differ from the cached values.
  3. Otherwise, the editor shows a labeled placeholder at the fallback's size. PDF export leaves the chart out with a drawing diagnostic.
  • 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.

See also