Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 ! :)

share|improve this question
1  
Which bug? atend is supported by epstopdf. –  Heiko Oberdiek Nov 7 '12 at 10:56
add comment

1 Answer

up vote 6 down vote accepted

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}
share|improve this answer
    
oh wow.. this works beautifully! Thanks so much.. appreciate it :) :) –  Ivan Nov 7 '12 at 12:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.