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

I want to create thumbnails from PDF files in order to be able to display a short preview of a PDF file on a website.

I tried this using ImageMagick. Unfortunately, the results are not very pleasant. 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 conversion team misconfigured or do you know the best way to achieve my goal?

+6
linux php pdf thumbnails screenshot
source share
2 answers

Your original pdf is smaller than the thumbnail you created. Imagemagick scales the image to the requested size. Use the following options:

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

The final > in the scale option tells Imagemagick not to scale the image to the size of the original.

Edit: Imagemagick uses Ghostscript to render PDF files. You can directly use Ghostscript if you need to set some parameters, for example resolution, to get the best image. The default resolution is 72 DPI, which means A4 paper is 595 x 841 pixels. With 150 DPI, you get twice as many pixels. For example.

 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 used by Imagemagick. Note the -r option, which sets the resolution to 150 DPI. You can use ImageMagick to scale the resulting image to a smaller size.

Using a higher resolution will reduce blur when resizing an image.

+5
source share

You can just use Google Docs.

 https://docs.google.com/viewer?a=bi&pagenumber=1&url=http://.../sample.pdf 
+3
source share

All Articles