Eric's Page

On This Site:

Nifty Hacks:

You Should Visit:

Projects I Manage:

Eric's EPS Cleaner

Introduction

One difficulty that often comes up in writing papers or books is how to create the figures and images. We have lots of tools available to us to make images, but it's often difficult to get high-quality images out of them for print purposes, and into tools that we use to compose our papers and books.

EPS is a format that should be ideal for this purpose, but (for a variety of reasons) isn't. Some tools have no "export EPS option." Of those that do, many tools produce broken or incompatible EPS files that cause problems later on, and there is no way (within those tools) to rectify this. This page describes a set of solutions to all these problems that I have found works extraordinarily well. Specifically:

  • How to use the Adobe EPS Printer Driver to generate EPS from tools that don't have an EPS export option.
  • How to construct Eric's EPS cleaner, a combination of open-source tools that can take nearly any EPS file (no matter how broken) and clean it up for perfect import into a document production tool or word processor.


Background

Encapsulated PostScript (EPS) is a very good format for print-quality graphics. It is almost universally supported by print shops, has good import support from most document creation applications (Word, FrameMaker, and so on), and has good support for vector art and mixed vector-bitmap art. EPS can also be converted to PDFs very well. PDF images are a marginally better option but fewer tools provide PDF image import capabilities.

EPS files are effectively PostScript files. When printed on a PostScript printer, the PostScript is sent to the printer directly. For on-screen display, EPS files can optionally contain a thumbnail bitmap that represents the PostScript content.

A major problem is that many implementations of EPS exporters are broken, or produce EPS files that have problems (missing thumbnails, slightly nonstandard PostScript that won't print) and so on. For example, it is basically impossible to export an EPS file from Microsoft Visio 2000, import it into Word, and print it on a PostScript printer without causing PostScript errors. This, as I understand it, is due to bugs in the Visio EPS export tool.


Approach: Generate EPS From Any Program

The first thing to do is to draw your graphics in your favorite graphics program and export them as EPS. Many graphics programs have an EPS export option already; this can be used for this purpose. If your favorite program lacks an EPS export option (e.g., Microsoft PowerPoint 2000) you can still export high-quality EPS by using an EPS printer driver. Luckily, Adobe distributes such drivers for free. Google for "Adobe postscript printer driver" or, for Windows, go here.

Once the driver is installed, add a new printer based on the generic PostScript driver and set it to print to a file. Then, go into the printer options, select 'Advanced' and PostScript options. Set the output format to Encapsulated PostScript. On Windows, the dialog looks like this:

Windows EPS Dialog

Once this is set up, you simply print the graphic to this virtual printer. The file that is output by the printing process will be an EPS file, and you should give it an .eps extension. Most programs will output high-quality vector EPS, including PowerPoint 2000.


Approach: Clean Up Grimy EPSes

As stated above, the output of many EPS exporters (including the Adobe printer driver from time to time) is less-than-perfect, which can cause problems during preview or printing.

Using a combination of open-source PostScript tools, it is possible to clean up these EPS files. This particular combination strips out extraneous data, optimizes the PostScript, and then generates and attaches a high-quality TIFF preview to the EPS file. These EPS files are often smaller than the original, print correctly, and have beautiful previews.

PREPACKAGED WINDOWS SOLUTION: You can download the cleaner as a package from here: epscleaner-win32.zip (10MB).

Unzip into a directory, and either set an environment variable EPSCLEAN to the unzip path, or edit cleaneps.cmd and cleancropeps.cmd to reflect the path. Skip to the next section if you use this method.

SETTING UP MANUALLY

Follow the instructions in this section if you don't want to use the prepackaged windows solution, or you're interested in setting up a cleaner for another platform and want to know how it works.

You will need:

Download and install these tools in some directory with an easy-to-type path.

Together, these tools have about ten zillion command-line options. I developed a set of Windows command files (batch files) to automate the cleaning of sets of EPS files. My files are available in a ZIP file from here, however, you'll need to modify them all to reflect the installation paths on your system.

Each of these should go in a directory on your PATH. The files I have developed are:

eps2eps.cmd: Cleans up a raw EPS file and strips out all extraneous data

cmd /c "set PATH=%PATH%;C:\Apps\gs\gs8.50\bin;C:\Apps\gs\gs8.50\lib&&call C:\Apps\gs\gs8.50\lib\eps2eps.bat -dSAFER %*"

Replace C:\Apps\gs\gs8.50 with your install location of GhostScript.

clean1eps.cmd: Cleans a single EPS file and adds a 300DPI TIFF preview

call C:\OnPath\eps2eps.cmd %1 cleaned.eps
del /q %1
C:\OnPath\epstool -t6p --dpi 300 cleaned.eps %1
del /q cleaned.eps

Replace C:\OnPath with the location of eps2eps.cmd and epstool.exe respectively.

cleaneps.cmd: Cleans one or more EPS files and accepts wildcards

for %%t in (%*) do call clean1eps %%t
pause

The pause is optional if you want to pause the output before the program terminates (useful if you drag and drop EPS files onto the cleaneps.cmd icon or a shortcut).

cleancrop1eps.cmd and cleancropeps.cmd: These files are basically identical to clean1eps.cmd and cleaneps.cmd except they also crop the EPS to get rid of all surrounding whitespace.


Using the Tools

To use the tools, update all the paths in the .cmd files and put them in a directory accessible from your PATH. To clean an EPS file, simply run:

cleaneps myfile.eps

To clean a bunch of EPS files you can use wildcards:

cleaneps *.eps

Alteratively, you can select a bunch of files in Windows Explorer and drop them on cleaneps.cmd or a shortcut to it.

If you want to crop whitespace, simply replace cleaneps with cleancropeps in the above command lines. clean1eps, eps2eps and cleancrop1eps are used by these scripts and should not be directly called by you.


Results

As an example, a small UML class diagram in Microsoft Visio 2000 with a TIFF preview attached exports as a 3.5MB EPS file that will not print properly on a PostScript printer. After running it through the cleaner, the EPS file shrinks to 65K and prints correctly.


Conclusions

That's pretty much it. I hope this helps someone. If you develop more platform-independent scripts or packaging for this approach, send them along and I'll happily host it. The tools used in this article are available for many different platforms and should work equally well on non-Windows platforms.

I am also considering setting this up as a Web service where you can upload a grimy EPS file and download a cleaned one. However, the upload-download process via a browser would be awkward from a UI perspective, so I just decided to provide the directions to install it locally here.