Page 1 of 1

Rasterize the PDF to a set resolution when reading it in

Posted: 2014-02-24T06:05:37-07:00
by henryoswald
I want to generate thumbnails of PDFs at a fixed width (548px wide, with the height determined by the PDF page aspect ratio). With ImageMagick, I can do this with the command:

Code: Select all

$ convert -density 300 -resize 548x input.pdf thumbnail.png
This works for arbitrary sized PDFs, however, the larger the PDF the longer it takes. From the documentation I understand that this is because ImageMagick first has to read in the PDF and rasterize it (at 300 DPI), before scaling it down. This obviously takes longer and more memory the larger the PDF is.

My question is: Can we tell ImageMagick to rasterize the PDF to a set resolution when reading it in (something like 2 or 3 times larger than the thumbnail needs to be) before scaling it down and outputting the PDF? This should allow our conversion to run in roughly the same amount of time regardless of the PDF size.

We can do this ourselves manually by reading the PDF resolution first and then calculating the appropriate DPI to generate a rasterized PDF of the right size, but this seems like a bit of a hack and I would expect something like this built into ImageMagick.

Re: Rasterize the PDF to a set resolution when reading it in

Posted: 2014-02-24T07:22:03-07:00
by dlemstra
We found 'your' post on stackoverflow and added a new feature that will be available in the next version of ImageMagick (6.8.8-8). I posted the following answer to the post on stackoverflow:

You can scale a PDF to a width of 548 pixels with the following command:

Code: Select all

$ convert -define psd:fit-page=548x input.pdf thumbnail.png
If you create an image with another DPI than the default (72 DPI) you will have to resize it afterwards:

Code: Select all

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

Re: Rasterize the PDF to a set resolution when reading it in

Posted: 2014-02-24T08:29:24-07:00
by henryoswald
Thats brilliant, thanks for being so responsive.

I will eagerly await for its release :D

Re: Rasterize the PDF to a set resolution when reading it in

Posted: 2014-02-27T02:47:25-07:00
by henryoswald
Out of interest how often do you release? Just wondering when 6.8.8-8 will be out.

Re: Rasterize the PDF to a set resolution when reading it in

Posted: 2014-02-27T09:48:03-07:00
by fmw42
As an observer, it can be any where between a few days to a couple of weeks or so.