I’ve been used the ImageMagick convert tool to make JPG images from PDF pages. Nothing too fancy, just generating a single 8.5 x 11 inch ratio JPG for each page in a PDF. This worked really well until I started seeing some PDF files generate the same size JPG, but instead of the page taking up the whole image it was about one quarter size, in the lower left corner.
Inspecting the PDFs showed that they had much larger dimensions. So I tried tweaking several settings; density, scale, resize and resample, all with no luck. No matter how I adjusted the settings I couldn’t get the page to use the whole image size. After more searching and trial and error I finally came across the information I needed to make this work, the define option. Specifically: -define pdf:use-cropbox=true
.
By default ImageMagick uses the MediaBox geometry to figure out the page size. But PDFs may have a CropBox or TrimBox value that is smaller than the MediaBox, which is exactly what I was looking for. From the ImageMagick PDF format description:
Requires Ghostscript to read. By default, ImageMagick sets the page size to the MediaBox. Some PDF files, however, have a CropBox or TrimBox that is smaller than the MediaBox and may include white space, registration or cutting marks outside the CropBox or TrimBox. To force ImageMagick to use the CropBox or TrimBox rather than the MediaBox, use -define (e.g. -define pdf:use-cropbox=true or -define pdf:use-trimbox=true). Use -density to improve the appearance of your PDF rendering (e.g. -density 300×300).
In my case adding the use-cropbox=true
fixed the problem.