[Tex/LaTex] I want \includegraphics{} to crop to the bounding box of an included PDF

bounding boxgraphics

Apparently, it's possible to use gs to automatically find the bounding box of a PDF. See https://stackoverflow.com/questions/10962235/how-to-find-blank-page-in-pdf-file/11274720#11274720.

What I would like to do is to have a way of including a bunch of images such as the bounding box is scaled to the box in which I want the image to be shown.

Any thoughts on how to do that?

Best Answer

Instead of doing this using \includegraphics{}, I would suggest a workaround to achieve the desired goal. If you are running on Linux/CygWin you can do the following in command line prompt:

for i in *.pdf
do
  oname=`basename $i .pdf`-old.pdf
  mv $i $oname
  pdfcrop --margins 0 $oname $i
done

After doing this, all the PDFs that were already in the directory will be renamed to *-old.pdf and the newly generated PDFs will be cropped tightly without white margin. Then you can use these PDFs in the TeX file without any trim option in \includegraphics{}.