Linux, EPS and Latex: Creating Good Quality EPS Graphics Using OpenOffice

If you use dvips and then ps2pdf to generate your PDF documents, you're no doubt using encapsulated postscript (EPS) files for your figures. The advantage to using EPS over formats like JPEG, GIF, or PNG is that EPS is a Vector Graphics format, which means that you can scale the image up or down without getting pixelation (check out the example on the Wikipedia page). For that reason, EPS graphics are very convenient to use in your latex documents because you can resize your figures easily depending on the document type. For example, if your document is in double column format, your figures will typically be 3.5 inches wide. If you change to single column format, you may want to enlarge your figures to 4.5-6.0 inches. If your images were GIF files, you may get pixelation, but EPS files will scale easily.

Furthermore, if you are using JPG/GIF files, for best results, you typically should create them knowing what size you'll be using (eg. 3.5in x 2in), and then import them without scaling them into your document. If you decide later on to scale them, you may run into pixelation problems again.

In short, the reason EPS graphics are preferred for Latex documents is because they offer greater flexibility with regards to scaling (no pixelation). But, there's a catch, you need to generate your EPS files properly, otherwise, you may end up with fuzzy blurred figures anyway.

Fuzzy/Blurred Figures

If you use EPS, you've probably noticed that your figures sometimes look fuzzy when viewed in your final PDF. You may have one or both of the following situations:

  • Lines and shapes appear fuzzy.
  • Text (fonts) appear fuzzy.

In most cases, the PDF will print properly, but the electronic version looks fuzzy in PDF because of resizing (viewing at 120% or 'page width', etc). The reason for this is that your EPS file was not properly generated by whatever program you used. Quite often, when using the 'save as' or 'export' feature of a program, the resulting EPS file doesn't have fonts embedded. You can check this by doing 'ps2pdf' and then 'pdffonts' to see if your fonts were embedded.

Fonts not embedded

If you have a figure with text where the fonts have not been embedded, you'll see no fonts listed by pdffonts:

$ ps2pdf14 bad.eps
$ pdffonts bad.pdf
name                                 type         emb sub uni object ID
------------------------------------ ------------ --- --- --- ---------

Fonts properly embedded

If your fonts have been properly embedded, you'll see something like the following output when running pdffonts:

$ ps2pdf14 good.eps
$ pdffonts good.pdf
name                                 type         emb sub uni object ID
------------------------------------ ------------ --- --- --- ---------
BAAAAA+ArialMT                       TrueType     yes yes yes      9  0

Generating 'Good' EPS Images

Many programs support EPS as a format you can save/export to, but they don't embed fonts properly. I've found two solutions to this problem, the first is to 'print-to-file' using a postscript printer driver, the second is to export to PDF using OpenOffice

Print to file

One of the easiest ways is to install a postscript printer driver and use the 'print to file' option. When you print to file, you'll end up with a postscript file which is a letter sized page. Since your figure is most likely smaller than a full page, you'll need to use something like 'ps2epsi' or 'ps2eps' to fix the bounding box. You should see after running 'pdffonts' on the resulting PDF file that all the fonts have been properly embedded.

Export to PDF (OpenOffice)

The best way I've found to create good EPS files is:

  • Use OpenOffice Draw to draw my figures.
  • Use the "Export to PDF" function because it embeds fonts properly.
  • Use 'pdftops -eps' to generate EPS files (note: not 'pdf2ps').
  • Optional: use ps2eps to fix the bounding box of the generated EPS file is needed.
  • Here's an example:

    $ pdftops -eps test.pdf
    $ cat test.eps | ps2eps > test2.eps
    Input files: -
    Processing: -
    Rendering with existing %%BoundingBox: 0 0 792 612
    Calculating Bounding Box...ready. %%BoundingBox: 32 47 760 569
    Creating output file -...ready.
    
    $ ps2pdf test.eps
    $ pdffonts test.pdf
    name                                 type         emb sub uni object ID
    ------------------------------------ ------------ --- --- --- ---------
    BAAAAA+ArialMT                       TrueType     yes yes yes      9  0
    
    $ pdffonts test2.pdf
    name                                 type         emb sub uni object ID
    ------------------------------------ ------------ --- --- --- ---------
    MFZMRR+ArialMT                       TrueType     yes yes no       8  0
    

    As you can see, the 'test.pdf' and 'test2.pdf' contain embedded fonts. So if you were to use the 'test.eps' file in your latex document, the resulting figure will not have fuzzy fonts when resizing the image.

    NOTE: If you simply convert a GIF to EPS, you're basically getting a GIF file embedded into the postscript file.

    UPDATE (17/11/2007): I've posted my oopdf2eps script that will convert your PDF to EPS using a single command.

Comments

This is brilliant! It solved

This is brilliant! It solved the problem bugging for such a long time. Thanks a lot!

Thank you!

Thank you very much for this post.

It was well written, easy to understand, and worked perfectly the first time I tried it.

-- A very grateful, LaTeX thesis-writing, grad student.

Thanks for this script!

Thanks for this script!

Thanks Thanks Thanks

It took me quite a while to figure out what the problem is...thanks for this nice workaround.

Cheers
martin

I owe you a beer ;)

Thank you very much! It works really good :)

Regards,
Dawid

Do not limit yourself to open office - use ps2pdf14 instead

I have a 7 simple steps to allow you to embed fonts in an EPS or PDF figure for use in a latex document, when the EPS or PDF figure is created from any drawing/picture software that does not automatically embed fonts e.g. MATLAB figures.

1. Save a Matlab figure from Matlab to EPS format.
2. Run ps2pdf14 -dPDFSETTINGS=/prepress unembedded_fig.eps embedded_fig.pdf.
Note: You can check the font is embedded by running
pdffonts embedded_fig.pdf
and check that the normal Helvetica font is embedd as BGISHF+Helvetica, for example.
3. You can either build your latex document with pdflatex, usepackage{graphicx} & \includegraphics{embedded_fig.pdf}, OR
4. run pdftops -eps embedded_fig.pdf embedded_fig.eps
5. run ps2eps embedded_fig.eps
which will crop eps to bounding box.
6. rename embedded_fig.eps.eps to embedded_fig.eps
7. Build your latex document with latex, usepackage{graphicx} & \includegraphics{embedded_fig.eps}.

Finally, check the font is embedded by running
pdffonts ~/my_article.pdf
and check that the normal Helvetica font is embedd as BGISHF+Helvetica.

Many Thanks

it helped me a lot :), thanks

manu

thanks :)
That worked like a charm.
Why the hell don't programs like inkscape or openoffice do this automatically? I almost went crazy trying to get the text in the eps to look good....

Yes, it is a pain that you

Yes, it is a pain that you have to sometimes go through a lot of gymnastics to get fonts to look good.

another method which works better for me

Thanks for writing this up. It did work for a few of my OpenOffice diagrams.

However, I found that it didn't work for all of them. Sometimes the initial pdftops call seems to not embed the fonts in the output. I haven't determined what it is about the diagrams in question where it doesn't do this.

I found a different method, which works nicely and is less steps on the command line:
1. draw what you want in openoffice
2. press Ctrl+A to select all
3. Right click on selection --> "Position and size"
4. Note the height and width
5. Format --> Page
6. Set the page width to width+0.2cm and the page height to height+0.2cm
7. Set all four margins to 0.1cm
8. Click OK to exit page setup
9. Find your selection again (it might be scrolled off to one side), right click --> "Position and size"
10. Set the X position to 0 and the Y position to 0

Now you end up with your diagram perfectly aligned on a perfectly sized canvas.

11. File -> Export as PDF

This gives you PDF output with fonts embedded and a correct bounding box (thanks to the paper size trick). I am using pdflatex directly so I can directly include the latex document with:

\includegraphics[width=XXmm]{filename.pdf}

However if eps output is needed for other environments I guess you could just one of the above tools to convert PDF to EPS hopefully without losing fonts and vectors.

- Daniel Drake

One small modification to fix missing bounding box errors in eps

Thanks, the above procedure worked well for me. However I had one small problem using this approach to produce eps files.

I followed the above approach and generated an eps version of the pdf using the "pdftops -eps" tool. However, opening the resulting eps file in GSview resulted in the following error: "eps file is missing the required %%boundingbox". I found that editing the eps file and double commenting the second line, i.e:

%% Produced by xpdf/pdftops 3.02

fixed the bounding box error.

-AE

Thanks, but I still need some help ...

... to make the correct bounding box for the eps file. When I export from OO, the bounding box appears to be the whole page. How could I make it to be the "correct" bounding box?

Thanks

ps2eps

The ps2eps program will fix the bounding box for you. You have to remember to use the "-eps" option. If you look at the output from ps2eps, you'll see that it spits out information about the bounding box:

$ pdftops -eps test.pdf
$ cat test.eps | ps2eps > test2.eps
Input files: -
Processing: -
Rendering with existing %%BoundingBox: 0 0 792 612
Calculating Bounding Box...ready. %%BoundingBox: 32 47 760 569
Creating output file -...ready.

Hugely helpful

Stephan, thank you very much.

Thank you

Thank you. You are a very good resource.

Glad to have helped. I

Glad to have helped. I should also mention that you can export EPS graphics with embedded Latin-1 or Pango fonts using Dia.

Can go direct to eps from OO, without intervening pdf file

If you are using OpenOffice 3.2 Draw (at least in Ubuntu), from File > Export... you can choose EPS (not pdf) as the output type and so do not need to run pdftops on a generated pdf file.

I believe the resulting eps file looks a bit better, both the fonts and the image. It is not perfect - lines that are not horizontal or not vertical are jagged, but fonts look OK.

You may still need ps2eps to set the bounding box. Note that, if you use OpenOffice 3.2 Impress instead of OO 3.2 Draw, ps2eps does not change the bounding box.

Hope this helps.