Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create thumbnails/screenshots out of PDF files on my Linux server?

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):

Bildschirmfoto 2010-09-11 um 22.57.49.png

Original PDF: (see Comment)

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

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

like image 670
Norwald2 Avatar asked Sep 11 '10 21:09

Norwald2


2 Answers

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.

like image 92
jmz Avatar answered Sep 18 '22 23:09

jmz


You can just use Google Docs.

https://docs.google.com/viewer?a=bi&pagenumber=1&url=http://.../sample.pdf
like image 36
David ZIP Avatar answered Sep 20 '22 23:09

David ZIP