开发者

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

开发者 https://www.devze.com 2023-01-15 13:58 出处:网络
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 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):

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

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?


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.


You can just use Google Docs.

https://docs.google.com/viewer?a=bi&pagenumber=1&url=http://.../sample.pdf
0

精彩评论

暂无评论...
验证码 换一张
取 消