EMF and WMF Files: Windows Vector Graphics Metafiles
EMF (Enhanced Metafile) and WMF (Windows Metafile) are vector graphics formats native to the Windows GDI (Graphics Device Interface) subsystem. Rather than storing pixels or geometric coordinates in an open standard, they store a sequence of GDI drawing commands — "draw this line here, fill this rectangle with this color, render this text in this font at this position." When played back, the GDI engine executes these commands to render the image at any resolution. This makes them resolution-independent vector formats, though they are deeply tied to the Windows platform.
WMF: The Original Windows Metafile (1990)
WMF was introduced with Windows 3.0 in 1990 as the standard clipboard and embedded graphics format for Windows applications. Every time you copied a chart from Excel 3.0 and pasted it into Word 2.0, you were using WMF. The format stores 16-bit GDI records:
WMF structure:
- 18-byte header (type, header size, Windows version, file size, object count, max record size, number of parameters)
- Sequence of variable-length records, each prefixed with a 4-byte size and a 2-byte function code
- Records directly correspond to GDI16 API calls:
SetMapMode,TextOut,Polygon,BitBlt, etc.
Limitations:
- 16-bit coordinate space — coordinates are restricted to integers in the range −32,768 to 32,767
- Device-dependent — assumes the same logical units as the source device
- No embedded color profiles, no transparency support
- Cannot embed fonts directly (only font references by name)
- Known security vulnerabilities — Windows XP/Vista had several remote code execution bugs in WMF parsing (the WMF exploit of 2005/2006 affected millions of systems)
WMF files use the .wmf extension. Placeable WMF (PLACEABLE, with a 22-byte prefix including a magic 0x9AC6CDD7) is a variant that embeds a bounding box for use in OLE containers.
EMF: Enhanced Metafile (1992)
EMF was introduced with Windows NT 3.1 and Win32 to address WMF's limitations. It stores 32-bit GDI32 records:
Key improvements over WMF:
- 32-bit coordinate space — sub-millimeter precision in device-independent units
- Embedded color profiles (optional)
- Better font handling — can embed partial font subsets
- More complete GDI32 function coverage
- Fixed-size header with well-defined signature
0x00000001in the first DWORD - Bounding box in device-independent units (0.01mm units)
EMF+ extension: Windows Vista introduced EMF+ which adds GDI+ drawing commands (gradients, anti-aliasing, alpha blending, Bezier curves, transformed images) alongside regular GDI records. EMF+ enables smooth gradients and semi-transparency not possible in plain GDI.
EMF files use the .emf extension. Dual EMF+/EMF files are supported — they contain both GDI and GDI+ records, playing back in GDI+ mode on Vista+ and falling back to GDI on older systems.
Practical Uses Today
Office Documents: Microsoft Office uses EMF/WMF internally for embedded graphics and clipboard operations. When you copy a vector chart from Excel and paste it into Word, Office internally uses EMF. When you export a Word document containing charts to PDF, Office renders the EMF to the PDF vector path commands.
Printing: The Windows print spooler uses EMF as its spool file format. Print jobs are recorded as EMF and then rasterized by the printer driver. This allows page zoom, page reordering, and print preview on recorded jobs.
Clipboard: The Windows clipboard still offers CF_ENHMETAFILE and CF_METAFILEPICT clipboard formats for vector data exchange between applications.
Legacy software: CAD programs, older diagram tools, and scientific visualization software from the 1990s–2000s often produce WMF/EMF output for Windows-specific vector export.
Opening and Converting EMF/WMF Files
Windows built-in: Windows Paint can open and display WMF files. XPS Viewer and Office applications can open EMF.
LibreOffice: Imports both WMF and EMF files natively. EMF support is especially strong in LibreOffice Draw and Impress.
Inkscape: Opens WMF and EMF files (using the UniConvertor backend). Vector paths, text, and basic shapes are usually preserved. Complex GDI operations (hatches, region clips) may not render correctly.
GIMP: Can import WMF/EMF by rasterizing them at a specified DPI. The result is a bitmap, losing vector scalability.
ImageMagick:
# Convert EMF to SVG
convert input.emf output.svg
# Convert EMF to PNG at 300 DPI
convert -density 300 input.emf output.png
# Convert WMF to PDF
convert input.wmf output.pdf
LibreOffice command-line conversion:
# EMF to SVG
libreoffice --headless --convert-to svg input.emf
# EMF to PNG
libreoffice --headless --convert-to png input.emf
unoconv (Python wrapper around LibreOffice):
unoconv -f svg input.emf
EMF/WMF to SVG: Challenges
Converting WMF/EMF to SVG is conceptually straightforward — both are vector formats — but practically messy:
- GDI operations without SVG equivalents: Hatch patterns, region clips, ternary raster operations (
ROP3) have no direct SVG analog - Font rendering: EMF embeds font references by name. If the font is not installed on the target system, SVG rendering will use a fallback, changing layout
- Coordinate system: WMF uses a device-dependent coordinate system that must be normalized to SVG's user units
- Text encoding: WMF uses Windows ANSI (CP1252) or Unicode; SVG is always UTF-8
Despite these challenges, LibreOffice and Inkscape produce reasonable SVG output for typical office-style EMF/WMF files (charts, diagrams, simple illustrations).
Security Considerations
WMF has a notorious security history. The SetAbortProc function in WMF records could execute arbitrary code when the file was rendered. Microsoft patched this in Windows XP SP2 and later, but the WMF attack vector demonstrated the danger of formats that execute code as part of rendering.
For untrusted WMF files:
- Convert to SVG or PNG in a sandboxed process before displaying
- Use LibreOffice headless conversion in a container/VM
- Never process untrusted WMF files using old, unpatched Windows systems
EMF has fewer historical vulnerabilities, but Microsoft's security bulletins have documented several EMF parsing vulnerabilities over the years. Always keep Windows updated.
When to Use EMF Today
EMF remains useful in one specific context: embedding vector graphics in Microsoft Office documents that must be shared with other Windows users. EMF graphics in Office documents scale without pixelation and print at full printer resolution. For any other use — web graphics, cross-platform exchange, archival — SVG or PDF are better choices with broader support.
Related conversions
Frequent conversions across the catalogue: