The perfect pdfcrop

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.


To expand on Ulrike's excellent answer:

The reason this is only guaranteed after rendering the font to an actual pixel map is that there is, in principle, no obligatory relation between a glyph's ink and its bounding box.

Here's an example; a lower-case 'm' from URW Nimbus Sans:

font view of a glyph m

The left and right sidebearings (the space between the ink and the bounding box) are shown. TeX , of course, sets to the bounding box, and not the ink 'for typographical reasons'.

If precision copyfitting before the final pixel map rendering is important for you, a solution which allows you to access the sidebearing values is available with XeTeX, as described in this question. However, this is not guaranteed 100%.


Expanding the comment of @ulrike-fischer, as it contains the solution that works in most of the cases I deal with - and as I guess this might help in many similar situations:

If your goal is to have no margins, and if pdfcrop crops/clips/moves parts of the content beyond the image borders, or if there remain some margins, then a combination of higher resolution (--hires) and larger image scaling (--resolution WIDTHxHEIGHT) might be a quick and practical solution:

pdfcrop --hires --resolution 1000x1000 my.pdf

If it needs to be more exact, then increase the resolution further:

pdfcrop --hires --resolution 50000x50000 my.pdf

In most cases I deal with this solves the problem in a quick and practical way, though there might be special cases where this is not exact enough.