Skip to the content.

wmf2svg - WMF/EMF Converting Tool & Library for Java

This project’s goal is to provide a Java tool and library for reading WMF/EMF files and rendering or writing them through GDI-compatible backends.

Command line

java -jar wmf2svg-[version].jar [options...] [wmf/emf filename] [svg/svgz/png/jpg/jpeg filename]

The output format is selected by the output filename suffix.

Options

If you render PNG/JPEG in a headless environment, specify Java’s headless mode at runtime as needed:

java -Djava.awt.headless=true -jar wmf2svg-[version].jar input.wmf output.png

It now requires Java 8.0 or later.

Library usage

The parsers replay metafile records to a Gdi implementation. Choose the implementation that matches the output you want.

SVG output

try (InputStream in = new FileInputStream("input.wmf");
		OutputStream out = new FileOutputStream("output.svg")) {
	SvgGdi gdi = new SvgGdi();
	new WmfParser().parse(in, gdi);
	gdi.write(out);
}

Use new EmfParser() for .emf input.

PNG/JPEG output

try (InputStream in = new FileInputStream("input.emf");
		OutputStream out = new FileOutputStream("output.png")) {
	AwtGdi gdi = new AwtGdi();
	gdi.setOpaqueBackground(true);
	new EmfParser().parse(in, gdi);
	gdi.write(out, "png");
}

AwtGdi renders through Graphics2D and writes raster images with ImageIO. Use "jpeg" to write JPEG.

WMF/EMF output

WmfGdi and EmfGdi record GDI calls and serialize them as WMF or EMF. This can be used to generate metafiles directly, or to transcode the supported subset of another metafile.

try (InputStream in = new FileInputStream("input.wmf");
		OutputStream out = new FileOutputStream("output.emf")) {
	EmfGdi gdi = new EmfGdi();
	new WmfParser().parse(in, gdi);
	gdi.write(out);
}
try (OutputStream out = new FileOutputStream("output.wmf")) {
	WmfGdi gdi = new WmfGdi();
	gdi.placeableHeader(0, 0, 1000, 1000, 1440);
	gdi.header();
	gdi.rectangle(100, 100, 900, 900);
	gdi.write(out);
}

Some advanced records are format-specific and may not be representable in the target metafile writer.

Maven repository

<groupId>net.arnx</groupId>
<artifactId>wmf2svg</artifactId>
<version>0.10.2</version>

Build

This project uses Maven to build a wmf2svg jar file.

mvn package

History

Copyright (c) 2007-2026 Hidekatsu Izuno, Shunsuke Mori All right reserved.