views:

34

answers:

1

I want to create thumbnails out of PDF files to be able to display a short preview of the PDF file on a website.

I tried it by using ImageMagick. Unfortunately the results aren't very pleasing. The resulting images are very fuzzy.

Example Thumbnail (fuzzy): http://cl.ly/7563000242690f0dec07

Original PDF: (see Comment)

Command: convert -thumbnail x800 k.pdf[0] test.png

I my convert command misconfigured or do you know any better way achieving my goal?

Thanks!

+2  A: 

Your original pdf is smaller than the thumbnail you're creating. Imagemagick scales the image to match the requested dimensions. Use the following parameters:

convert -scale '800x800+0+0>' -colorspace rgb -strip in.pdf[0] out.png

The trailing > in the scale parameter tells Imagemagick to not scale the image to larger than the original.

Edit: Imagemagick uses Ghostscript to render PDF files. You can use Ghostscript directly if you need to set some parameters, like resolution to get a better image. Default resolution is 72 DPI which means that an A4 paper has size of 595 x 841 pixels. With 150 DPI you'll get twice the number of pixels. E.g.

gs -q -dBATCH -dNOPAUSE -sDEVICE=pngalpha -dMAxBitmap=500000000 -dAlignToPixles=0 -dGridFitTT=0 -r150x150 -sOutputFile=out.png in.pdf

The above command is almost identical to the one Imagemagick uses. Note the -r parameter which sets 150 DPI resolution. You can use ImageMagick to scale the resulting image to smaller size.

Using a higher resolution will reduce fuzziness when you resize the image.

jmz
Thanks! But there is still a huge difference. PDF: http://cl.ly/2aafb79d30d263fe783b Image: http://cl.ly/f76642c45fbd45532789
Norwald2
I updated the answer with the GS command to get a better resolution image from your pdf. Note that the PDF screencapture and resulting image are of different size. If I convert the first image to the same width as the second image has, the resulting image is equally fuzzy. You can reduce fuzziness (some) by using a higher resolution source image. It also helps if you'll be creating 800 pixel wide images, since A4 at 72 DPI is 595 pixels.
jmz