19

I need a "perfect" pdfcrop, one that crops exactly to the edge of the figure or text for alignment issues as a graphic in other programs. I'm aware of the standalone package, and have gone through all the questions on pdfcrop including the --hires option. Neither solution crops to exactly to the edge. For example, using standalone:

\documentclass[crop]{standalone}
\begin{document}
Hi
\end{document}

enter image description here

and using pdfcrop --hires:

enter image description here

As you can see, pdfcrop is close, but I need something exact. I think that standalone only knows the width given by the glyphs and pdfcrop gets its information from gs. Is it possible to achieve a perfect crop using LaTeX or any external tool?

Hooked
  • 4,046
  • A better test example is Ag\"e as you will also see the most top and bottom parts. – kiss my armpit Jul 03 '12 at 03:38
  • 1
    I don't have this software, but the crop feature in Adobe Acrobat (Standard or Pro) might be worth trying. If I remember correctly, there is a feature in the crop tool to remove surrounding white space. – JohnReed Jul 03 '12 at 05:36
  • 1
    @JohnReed: The feature is there but has similar “problems” like the other mentioned tools. So better trying before buying ;-) – Chris Jul 27 '12 at 11:38
  • See also https://tex.stackexchange.com/questions/275374/what-is-the-local-height-of-a-capital-letter/275381#275381 – Steven B. Segletes Aug 19 '19 at 16:34

3 Answers3

17

To be able to crop a vector graphic reliably you must "print" it to see where the black dots are.

"Printing" always involves a resolution: the black dots must have a positive size.

pdfcrop uses the bbox device of ghostscript. According to the documentation of ghostscript the default resolution of this device is 4000 dpi.

You can change this resolution but simply enlarging it doesn't mean that you get a more "perfect" result: To be able to decide if a crop is "perfect" you must "print" it e.g. to a screen to see where the black dots are and on the lower resolution of the screen you will see your "exact" crop only at a very large zoom.

Ulrike Fischer
  • 327,261
  • 1] Is there a way to get a higher resolution than the setting of --hires (which I'm assuming is the 4000 dpi you are talking about)? 2] If a vector graphic is simply a collection of (bézier?) curves, isn't it possible to mathematically determine the bounding box without printing? – Hooked Jul 03 '12 at 12:59
  • 1
  • Theoretically yes. I can e.g. do something like this: C:\Test>mgs -dNOPAUSE -dBATCH -sDEVICE=bbox -r8000 -g800000x800000 test-utf8.pdf (mgs is the ghostscript in miktex). 2. I have no idea how difficult if would be to calculate a perfect resolution independant bounding box: But as the dots on your screen have a size they will no be able to stop exactly at this bounding box. You can't avoid the resolution issue. (And naturally the values don't need to be rational numbers).
  • – Ulrike Fischer Jul 03 '12 at 13:20