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

TypeFormatComponent
Raster imagesJPG, PNG, GIF, BMP, TIF, ICOImageRun
Vector imagesSVG (with fallback)ImageRun
EMF/WMFEMF, WMFImageRun

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 Media class for managing media relationships
  • Embedding video thumbnails as images with hyperlinks to online video URLs

ImageRun Options

OptionTypeDescription
typestringImage format ("png", "jpg", "gif", "bmp", "svg")
dataBuffer | Uint8Array | stringImage data (buffer or base64)
transformationobject{ width, height } in pixels
floatingobjectFloating positioning (anchor or inline)
altTextobject{ 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" },
            },
        }),
    ],
});
Copyright © 2026