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

TypeFormatRun Type
Raster imagesJPG, PNG, GIF, BMP, TIF, ICO{ image }
Vector imagesSVG (with fallback){ image }
EMF/WMFEMF, 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

OptionTypeDescription
widthnumber | UniversalMeasureDisplay width (number = EMU)
heightnumber | UniversalMeasureDisplay height
dxaOrignumberOriginal width in twips
dyaOrignumberOriginal height in twips
iconImageobjectPreview { data, type, title? }
embedobjectEmbedded OLE { data, progId?, drawAspect?, fieldCodes? }
linkobjectLinked OLE (extends embed with updateMode)
controlobjectActiveX control { rId, name?, shapeid? }
moviestringMovie 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

OptionTypeDescription
typestringImage format ("png", "jpg", "gif", "bmp", "svg")
dataBuffer | Uint8Array | ArrayBuffer | string (data URL)Image data (buffer or base64)
transformationobject{ width, height } in EMU or UniversalMeasure
floatingobjectFloating positioning (anchor or inline)
altTextobject{ title, description } for accessibility
Copyright © 2026