DOCX
Media
Embedded media support in Word documents
Word documents can embed various media types. This package provides support for images through the image run type, which is the primary media type used in DOCX files.
For detailed image documentation, see Images.
Supported Media Types
| Type | Format | Run Type |
|---|---|---|
| Raster images | JPG, PNG, GIF, BMP, TIF, ICO | { image } |
| Vector images | SVG (with fallback) | { image } |
| EMF/WMF | EMF, WMF | { image } |
Video and Audio
The OOXML specification supports embedded video and audio through media relationships, but playback depends on the application opening the document. For complex media embedding scenarios, consider:
- Using the media utilities for managing media relationships
- Embedding video thumbnails as images with hyperlinks to online video URLs
OLE Objects
Embed OLE objects (e.g. Excel sheets, ActiveX controls) inline via the object run child. The object renders a VML preview (iconImage) and references the embedded binary (embed):
import { generateDocument } from "@office-open/docx";
await generateDocument({
sections: [
{
children: [
{
paragraph: {
children: [
{
object: {
width: "5.3cm",
height: "2.6cm",
iconImage: { data: iconBytes, type: "emf", title: "Excel Sheet" }, // preview
embed: {
data: oleBytes, // Uint8Array or base64 data URL
progId: "Excel.Sheet.12",
drawAspect: "icon", // "content" | "icon"
},
},
},
],
},
},
],
},
],
});
Object Options
| Option | Type | Description |
|---|---|---|
width | number | UniversalMeasure | Display width (number = EMU) |
height | number | UniversalMeasure | Display height |
dxaOrig | number | Original width in twips |
dyaOrig | number | Original height in twips |
iconImage | object | Preview { data, type, title? } |
embed | object | Embedded OLE { data, progId?, drawAspect?, fieldCodes? } |
link | object | Linked OLE (extends embed with updateMode) |
control | object | ActiveX control { rId, name?, shapeid? } |
movie | string | Movie relationship id |
embed.data and iconImage.data accept Uint8Array or a base64 data URL. Parsing round-trips w:object back into the same { object } run child.
Image Options
| Option | Type | Description |
|---|---|---|
type | string | Image format ("png", "jpg", "gif", "bmp", "svg") |
data | Buffer | Uint8Array | ArrayBuffer | string (data URL) | Image data (buffer or base64) |
transformation | object | { width, height } in EMU or UniversalMeasure |
floating | object | Floating positioning (anchor or inline) |
altText | object | { title, description } for accessibility |