Using Visio to Produce EPS files for LyX / LaTeX

Converting Visio files to .eps for embedding in LaTeX


Anyone who has used Visio will know that the EPS (Encapsulated Postscript) export facility is severely broken. Very often, the image will come out completely black, and even when this is corrected, the image often has pieces missing, or just plain wrong, and the file is not viewable with GhostScript.

Note: the above is true for Visio 4.0; feedback I get from correspondants unfortunately seems to indicate that things haven't improved with more recent versions.


With the later versions of Visio (I use Visio Professional 2002 now), it seems that setting the "Include AI format" checkbox (include Adobe Illustrator code) allows direct saving of .eps files that LyX and LaTeX can read.

The files have errors (e.g. "The number of Begin and End comments do not match"), but (at least) that error doesn't appear to be fatal. You may need the latest .eps viewing tools, e.g. gsview32.exe version 4.0 or later.

Therefore, if you have a later version, use the below as a last resort only.


The best workaround that I have found is to print to a suitable printer driver that has an EPS option, and then hack the bounding box manually. The trick is to find the right postscript printer driver; many don't have an EPS option, and EPS is NOT just Postscript with a special header. (See the FAQs from sites like Internet resources for Postscript & Ghostscript" for details). A good driver is available from Adobe. It is most unlikely that typical drivers (like HP laserjet drivers) will work!  The Adobe download page (at present!) is http://www.adobe.com/support/downloads/main.html; look for Printer Drivers then Macintosh or Windows as appropriate, and look for a driver with a name like Adobe Universal PostScript Windows Driver Installer 1.0.6 (for Windows 95, 98, Me, NT 4.0, and 2000) - English. As of June 2002, the direct link (for Windows) is this, but it can change very quickly.

When the printer is set up, make sure that the options are set correctly; in particular, use Settings/Printers and right click on the new printer. (These instructions are for Windows NT; it may differ for Windows 95/98/etc). Under "Document Defaults" choose the "Advanced" tab, and under "Document Options" expand "Postscript Options". Under "Postscript Output Option" select "Encapsulated Postscript (EPS)". In may as well also change some Properties (on the popup menu), "Ports" tab, and choose the "FILE:" port. In fact, this is just in case you forget to check the "print to file" option when printing; this allows you to choose the path more sensibly. Save the file as ".ps", since you still have to modify the bounding box (see below) to make a true .eps file.

When this is all set up, then you can output anything (including but not limited to Visio drawings) to an EPS file by printing to that special "printer". (Just ignore the "Save as" option in Visio).

To use the EPS file as saved above with Latex, you still need to change the bounding box of the EPS file (Visio always seems to print the whole page, so the bounding box is set to whatever page you set up in Visio). That means that diagrams will wipe out all the other text on the LaTeX page. This can be done most readily by using gsview for Windows. (Note: you also need ghostscript, fonts, and another file; read the notes on those pages carefully). It has the facility for calculating a tight bounding box and saving the file with the new bounding box (under File PS->EPS). (The file still has to be EPS suitable, so it is still important to use the right printer driver to generate good EPS).

You can also do this manually; you will find it easier if you put your diagram in the bottom left corner of the page, about a centimeter from the edges. Then just edit the EPS file; about the fifth line should read something like

%%BoundingBox: 17 22 578 820
These dimensions are in points (approx. 1/72"), and represent the x and y co-ordinates of the bottom left and top right corners of the drawing. I measure with a ruler, add 10% or so, and put in the appropriate figures in the third and fourth numbers, then use Ghostscript to check that I have not cut off too much or too little. For example, suppose the diagram is 75mm wide by 100mm high; that's about 3" x 4". You could start with 225 and 300 for the second and third numbers. Leave the first two numbers alone.

I should add that Visio is otherewise a very good product, and I really hope that the EPS exporting is fixed in the next version (version 5 still has the problem).

What about converting to .gif?

Converting to .gif's (e.g. for web pages) is quite easy. Just use File/SaveAs and save as a .bmp file, choose 96x96 DPI, 16 colours, then use any paint program to convert from .bmp to .gif (I use progressive mode for web images, though at about 12k for a large diagram, it's not even necessary!)

Converting eps files for use in PowerPoint

Surprisingly, Visio is very good at reading .eps files, and PowerPoint is very bad at displaying .eps files. (PowerPoint seems to get the text especially bad). All Windows programs seem to cope with Windows Metafile Format (.wmf) however. So if you have some .eps files that want to embed into PowerPoint presentations, this is the best way (that I found).

Start with a blank Visio page. Use Insert / Picture / From file, to insert the .eps file. If all goes well, you can just use File / Save as, select .wmf format, and save the file. You can just press the delete key to restore the blank page, and repeat for as many .eps files as need to be converted.

Things can go wrong, however. Often, the problem is a non standard character in the .eps file. To correct these problems, you need to ungroup (control shift U) the parts of the drawing. This unleashes its own set of bugs with Visio - now some of the text may be split into pieces, often overlapping. The only way to fix this is manually. I stay in pointer mode; switching continually betweeen pointer and text mode is most vexatious. It does mean that when selecting text, it will all be selected, so you need to be careful and press the end key to add text at the end. You'll see what I mean when you try it. I find that if you left justify the text, it will end up in just the right position (so you may as well stretch the text box nice and large, so it won't overflow as you add text).

You can use the character map tool (comes with Windows; usually under Programs / Accessories / System Tools) to add any special symbols in the Windows way, which should work with other Windows programs. Before saving, group the components with control shift G; then File / Save as will save the whole drawing.

Last modified 06 Jun 2002: Updated Adobe Universal postscript driver links, gsview links