Using the graphicx package with pdfLaTeX and LaTeX

The Problem

I use graphicx for images in LaTeX. It works fine with ordinary LaTeX but when I run pdfLaTeX the images are not visible in the PDF.

The graphicx package which is the package for inserting images seems to have no real understanding of the images at all. What it does when LaTeX runs is basically insert a small piece of wrapper information into the DVI, something like:

<Here Beginneth a Piece of Encapsulated Postscript>

.... It inserts the eps file verbatim here .....

<Here Endeth the Postscript>

So, what happens is

  • The DVI viewer may have a limited knowledge of postscript and can then display the image
  • DVIPS just leaves it in place
  • When you read/print the postscript, the image appears as a piece of Encapsulated Postscript within the outer Postscript document. This works fine.
  • PDFLaTeX probably inserts the eps the same way. The result is a big piece of encapsulated postscript in the middle of the PDF. This is not valid so the images don't get displayed in your PDF Viewer.

The Solution

As you need to insert EPS images in Postscript, you need to insert PDF images into PDFs. This is actually pretty straightforward. There is in UNIX a command called eps2pdf. This will do the conversion. The tool also exists in Windows though under the slightly different name epstopdf. You _can_ do this with photoshop but it's far more tedious and the quality is no better.

  1. Open up a DOS or UNIX shell.
  2. cd to the directory you have the files in.
  3. For each image called eg myimage.eps do
    epstopdf myimage.eps

This should leave you with both pdf & eps images (which is what you want). Now in LaTeX, you may have noticed that the file extension is often optional, ie you can put 'myimage.eps' or just 'myimage' and TeX will figure it out. If you give 'myimage' to Graphicx/pdfLaTeX it'll use 'myimage.pdf'.

So, all you have to do in your LaTeX is omit the extension in order that TeX gets to decide which image it should use. If you run LaTeX it'll use the .eps and if you run PDFLaTeX it'll use the .pdf.

Worth noting is that the EPS images produced by some graphics programs (eg Photoshop) is less than perfect. In running epstopdf I sometimes get "Bounding Box Not Found" errors. The solution has been to first run eps2eps or possibly ps2ps on them first. These programs rationalize the postscript and give back a semantically better file. To quote the linux manual page:

ps2ps uses gs(1) to convert PostScript(tm) file "" to simpler, normalized and (usually) faster PostScript in ""