41

I'd like to try to use pdfLaTeX to generate PDFs but my images are all in EPS. I would also like for the images to remain scalable.

I have tried using ImageMagik's convert:

convert file.eps file.pdf

but the result does not look good and the image becomes grainy after a few zooms.

I try epstopdf file.eps, but get the following error message:

Error: /undefined in II*
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1878   1   3   %oparray_pop   1877   1   3   %oparray_pop   --nostringval--   1861   1   3   %oparray_pop   1755   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1160/1684(ro)(G)--   --dict:1/20(G)--   --dict:89/200(L)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 8.71: Unrecoverable error, exit code 1

which doesn't really tell me anything.

Anyone know any other ways to convert EPS to PDF? (I have about 200 images, so command-line is better)

Martin Scharrer
  • 262,582
Noli
  • 1,551

3 Answers3

31

epstopdf, of course, which is what the epstopdf package relies on. (If you used the package there would be no need to convert.)

Or is that what you meant by eps2pdf? I've never noticed any problems with it.

I suppose you could also try Inkscape; I think it does have some batch functions, perhaps even command-line options for conversion, even though it is principally a GUI app.

EDIT: Judging by the inkscape manual, you could just do:

inkscape --export-pdf=output.pdf input.eps

EDIT2: Actually, you might need to use SVG input for inkscape export on the command-line; I'll look into this a bit more. You could do it through the GUI, though.

Martin Scharrer
  • 262,582
frabjous
  • 41,473
  • sorry... yeah, mistake... I meant epstopdf – Noli Sep 08 '10 at 03:11
  • The epstopdf package relies on \write18 being enabled. It's a nice feature, but a bad idea. Just run epstopdf yourself. – TH. Sep 08 '10 at 06:30
  • @TH: You could just pass the appropriate command-line flag to pdflatex, which you can find in the epstopdf manual... – SamB Sep 14 '10 at 22:50
  • +1 for inkscape which works really nice for me. No issues with font changes etc. so far. – Martin Scharrer Jul 06 '11 at 13:32
  • Thanks, very useful. I managed this on WSL2 inkscape install on a folder with many eps using this magic for i in *.eps; do echo $i; inkscape --export-pdf=${i%.eps}.pdf $i; done. See https://unix.stackexchange.com/questions/19654/how-do-i-change-the-extension-of-multiple-files – tobi delbruck Oct 11 '23 at 07:19
7

You can use ps2pdf with options to suppress resampling and lossily compressing images -dAutoFilterColorImages=false and -dColorImageFilter=/FlateEncode. (On windows, replace the = by #).

ps2pdf may not keep the same bounding box, unlike epstopdf, but you can fix that either by copying the logic from epstopdf (eg, edit epstopdf.pl to add those options to the ghostscript command line) or you can redo the clipping by using pdfcrop.

Lev Bishop
  • 45,462
  • With those flags, will ps2pdf also avoid decoding images using the DCTEncode filter, such as would be produced by losslessly converting a JPEG file to EPS with http://pts.szit.bme.hu/sam2p/? – SamB Sep 14 '10 at 23:09
  • 1
    @SamB Adobe Distiller (since version 6) has a parameter PassThroughJPEGImages. Unfortunately, ghostscript (the engine underlying ps2pdf) does not support this distiller parameter. See item 3.8 in the ghostscript projects page (has been a project since 2000, don't hold your breath). Because of this, sam2p is much less useful than it seems at first, and using eps as an intermediate format on the way to pdf is not attractive.... See this answer – Lev Bishop Sep 14 '10 at 23:39
4

I always use the following batch file

echo off
latex %1
del %1.log
del %1.aux
dvips %1 -E -o %1-crop.eps
del %1.dvi
epstool --copy --bbox %1-crop.eps %1.eps
del %1-crop.eps
epstopdf --hires %1.eps

in my job to compile an example:

% gridoff.tex
\documentclass{minimal}
\usepackage{pstricks}

\pagestyle{empty}
\begin{document}

\begin{pspicture}[showgrid=false](3,3)
\pscircle(1.5,1.5){1}
\rput[tr](3,3){3}
\end{pspicture}

\end{document}

It runs without problem. The important parts that you need are

epstool --copy --bbox input.eps output.eps
epstopdf --hires output.eps

The first invokes GhostScript to append high resolution bounding box. The last converts EPS to PDF with high resolution bounding box.

Martin Scharrer
  • 262,582
Display Name
  • 46,933