pyemf is a pure python module that provides bindings for an ECMA-234 compliant vector graphics library. ECMA-234 is the published interface for the Windows GDI used in the Microsoft windows environment and, more importantly, natively supported by the OpenOffice suite of tools.

EMF Overview

An Enhanced Metafile (EMF) is a vector graphics format developed by a certain company in Redmond, WA that is a native format in Windows. It supports a fairly robust set of graphics primitives like lines, arcs, bezier curves, and fonts, and has the ability to use linear transforms to rotate, scale, shear, and translate from the world coordinate system onto the page.

The important application in the open source community is through OpenOffice and its ability to read RTF files. With the Python libraries PyRTF and Matplotlib hopefully soon including EMF support (patches have been submitted), it is possible to create a single file that includes both text and graphics, and is usable on Windows, Linux/Unix, and MacOS.


I needed to have some way to generate reports with both text and graphics, and to be able to email those reports to people who use Windows. The users also needed they ability to cut out the graphics and paste them into powerpoint slides. My one real requirement was vector graphics so that the resulting powerpoint wouldn't look nasty when the graphics were resized.

Initially thought about HTML, but it's inconvenient emailing a zip file full of multiple files. There is a format called "MHTML" that allows images and text to be included in a single file, but it is non-standard. I then thought about PDF and EPS, and went down that road for a while with the very nice toolkits ReportLab and Matplotlib. But, PDF (or at least Adobe Reader on Windows) has the restriction that you can't copy EPS figures from within a PDF and paste them anywhere. So, that turned out not to be a workable solution.

I had to build pyemf because this is the only way I could automate document generation via Python that:

  1. uses vector (scalable) graphics
  2. allows bundling of multiple graphics files and text into a single file (via PyRTF)
  3. was cross platform (I run Linux but had to support the Windows world)


Not knowing anything about Windows graphics files, I stumbled upon libEMF and searched in vain for a python binding for libEMF. Not having found one, I actually wrote a version 1.0 of pyemf using SWIG to create a wrapper around libEMF.

But, before even officially releasing pyemf 1.0, but decided to write pyemf 2.0 as a pure python implementation . That means that all the time I spent building (and debugging!) pyemf 1.0 really became an exercise to learn how SWIG works. But, that's OK, because there were a few features left out of libEMF that I can now add in without waiting for them to be added to libEMF.

I've submitted patches to the maintainers of PyRTF and Matplotlib, and can now generate RTF documents that include snazzy scientific plots. These documents are modifiable by both Microsoft Word and OpenOffice Writer, satisfying the need to be cross platform.

When SVG is understood by Word (OpenDoc nudge, nudge, say-no-more?), EMF will become unnecessary, but this can fill the void in the meantime.

Current Version

pyemf 2.0.0, released 01 January 2006. Available at the download page. Patches for PyRTF and matplotlib included.

See the roadmap for known issues and future directions.

pyemf is licensed under the LGPL