Rasterize the PDF to a set resolution when reading it in

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
henryoswald
Posts: 5
Joined: 2014-02-24T06:03:38-07:00
Authentication code: 6789

Rasterize the PDF to a set resolution when reading it in

Post 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.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

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

Post 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
Last edited by dlemstra on 2014-02-24T09:24:14-07:00, edited 1 time in total.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
henryoswald
Posts: 5
Joined: 2014-02-24T06:03:38-07:00
Authentication code: 6789

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

Post by henryoswald »

Thats brilliant, thanks for being so responsive.

I will eagerly await for its release :D
henryoswald
Posts: 5
Joined: 2014-02-24T06:03:38-07:00
Authentication code: 6789

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

Post by henryoswald »

Out of interest how often do you release? Just wondering when 6.8.8-8 will be out.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

As an observer, it can be any where between a few days to a couple of weeks or so.
Post Reply