RMagick — Use CropBox when converting PDF to JPG

Ken Greeff
Realhub
Published in
1 min readFeb 13, 2019

--

Chop it down to size

Just a quick tip in case someone else runs in to it as it took me a while to find the correct setting when searching.

This assumes your pdf is supplied as a blob and you are using the Magick::Image::from_blob method.

The default ImageMagick option when using the convert command line tool is -define pdf:use-cropbox=true. To achieve the same thing in RMagick you can pass the following in the options block:

image = Magick::Image::from_blob(pdf_blob) do
self.format = 'PDF'
self.define("pdf", "use-cropbox", true)
end

You can read more about the RMagick define method here:

https://rmagick.github.io/info.html#define

--

--