Imagemagick: rasterize a PDF to a given resolution when reading it in

I want to generate thumbnails of PDF files with a fixed width (548 pixels wide, height depends on the PDF page format). With ImageMagick, I can do this with the command:

$ convert -density 300 -resize 548x input.pdf thumbnail.png

This works for arbitrary size PDF files, however, the larger the PDF, the longer it takes. From the documentation, I understand that this is because ImageMagick must first read in PDF and rasterize it (at 300 DPI) before scaling it. This obviously takes more time and more memory than more PDFs.

My question is: can we tell ImageMagick to rasterize the PDF to the given resolution when reading it (something like 2 or 3 times what the thumbnail should be) before scaling it and displaying the PDF file? This should allow our conversion to work at about the same time regardless of the size of the PDF.

We can do this on our own by first reading the PDF resolution and then calculating the appropriate DPI to create the rasterized PDF file of the desired size, but it seems to hack, and I would expect something like that built into ImageMagick.

+3
source share
1 answer

This is not possible in the current version of ImageMagick (6.8.8-7). We found your post here and added the following function, which will be available in ImageMagick (6.8.8-8):

PDF 548 :

$ convert -define psd:fit-page=548x input.pdf thumbnail.png

DPI, (72 DPI), :

$ convert -density 300 -define psd:fit-page=548x input.pdf -resize 548x thumbnail.png
+9

All Articles