DOCX
Media
Embedded media support in Word documents
Word documents can embed various media types. This package provides support for images through ImageRun, which is the primary media type used in DOCX files.
Supported Media Types
| Type | Format | Component |
|---|---|---|
| Raster images | JPG, PNG, GIF, BMP, TIF, ICO | ImageRun |
| Vector images | SVG (with fallback) | ImageRun |
| EMF/WMF | EMF, WMF | ImageRun |
Image Insertion
Images are the most commonly embedded media.
import { Paragraph, ImageRun } from "@office-open/docx";
new Paragraph({
children: [
new ImageRun({
type: "png",
data: imageBuffer,
transformation: { width: 200, height: 150 },
}),
],
});
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
Mediaclass for managing media relationships - Embedding video thumbnails as images with hyperlinks to online video URLs
ImageRun Options
| Option | Type | Description |
|---|---|---|
type | string | Image format ("png", "jpg", "gif", "bmp", "svg") |
data | Buffer | Uint8Array | string | Image data (buffer or base64) |
transformation | object | { width, height } in pixels |
floating | object | Floating positioning (anchor or inline) |
altText | object | { title, description } for accessibility |
Floating Images
Position images freely on the page using floating mode:
new Paragraph({
children: [
new ImageRun({
type: "png",
data: imageBuffer,
transformation: { width: 200, height: 150 },
floating: {
horizontalPosition: { relative: "page", align: "center" },
verticalPosition: { relative: "page", offset: 1440 },
wrap: { type: "none" },
},
}),
],
});