5

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?

  • 4
    Just to be clear: Your included image has some surrounding white space that you want to automatically trim and insert into your document constrained to some fixed width and height? Why not just pre-process the (all) image(s) to have tight bounding boxes before you include them? – Werner Jul 5 '13 at 1:52
10

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{}.

  • This method is as per Werner's comment. – Jagath Jul 5 '13 at 2:47
  • Wow. That's great. I didn't know about pdfcrop. Thanks. – vy32 Jul 6 '13 at 1:08
  • Ps - as an aside, pdfgcrop is a perl script that runs GhostScript – vy32 Jul 6 '13 at 3:39
  • pdfcrop does not get the bounding box right, always, for me. Inkscape (command line/script) is still the only sure way I have found to correctly find the bounding box in an automated way, especially for text axis labels, and for whitespace beyond them. It's ungainly, though. – CPBL Jul 6 '16 at 15:38
  • I tried pdfcrop, it turned a 1MB PDF file into an 8MB PDF file. – Alexey Nov 25 '17 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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