2

Currently, my epstopdf is not able to convert eps to pdf correctly due to the boundingbox (atend) bug that the epstopdf does not support. However, I intend to use pdfcrop on the generated pdf file and that usually fix the white space problem. However, I have to manually fix every generated file. Is there a way to automate this in latex? For example, automatically calling pdfcrop immediately after epstopdf. I tried using DeclareGraphicsRule in epstopdf but it wasn't working.

Please advise. Thanks a lot ! :)

1
  • 1
    Which bug? atend is supported by epstopdf. Commented Nov 7, 2012 at 10:56

1 Answer 1

6

The following adds an option crop to graphicx/\includegraphics. If enabled, it adds pdfcrop to the conversion of .eps to .pdf.

Because pdfcrop is not added to the restricted shell escape command list, full shell escape is needed: --shell-escape (TeX Live) or --enable-write18 (MiKTeX).

If the file is converted and uptodate, changing the option crop does not have an effect. Also the option does not affect other image files.

\usepackage{graphicx}
\usepackage{epstopdf}

\makeatletter
\newif\ifGin@pdfcrop
\Gin@pdfcroptrue
\define@key{Gin}{crop}[true]{%
  \csname Gin@pdfcrop#1\endcsname
}
\epstopdfDeclareGraphicsRule{.eps}{pdf}{.pdf}{%
  epstopdf --outfile=%
  \ifGin@pdfcrop
    tmp-image.pdf #1 &&
    pdfcrop tmp-image.pdf \OutputFile
  \else
    \OutputFile\space#1%
  \fi
}
\makeatother

Example usages:

\includegraphics{foo1}
\includegraphics[crop]{foo2}
\includegraphics[crop=false]{foo3}
\setkeys{Gin}{crop}
\setkeys{Gin}{crop=false}
1
  • oh wow.. this works beautifully! Thanks so much.. appreciate it :) :)
    – Ivan
    Commented Nov 7, 2012 at 12:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .