如何在Linux服务器上用PDF文件创建缩略图/屏幕截图? [英] How to create thumbnails/screenshots out of PDF files on my Linux server?
问题描述
我想从PDF文件中创建缩略图,以便能够在网站上显示PDF文件的简短预览.
I want to create thumbnails out of PDF files to be able to display a short preview of the PDF file on a website.
我通过使用ImageMagick进行了尝试.不幸的是结果并不令人满意. 生成的图像非常模糊.
I tried it by using ImageMagick. Unfortunately the results aren't very pleasing. The resulting images are very fuzzy.
缩略图示例(模糊):
原始PDF :(请参阅评论)
Original PDF: (see Comment)
命令:convert -thumbnail x800 k.pdf[0] test.png
我的转换命令是否配置错误?或者您知道实现我的目标的更好方法吗?
Is my convert command misconfigured or do you know any better way achieving my goal?
推荐答案
您的原始pdf小于您创建的缩略图. Imagemagick缩放图像以匹配请求的尺寸.使用以下参数:
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
scale参数中的尾随>
告诉Imagemagick不要将图像缩放到比原始图像大.
The trailing >
in the scale parameter tells Imagemagick to not scale the image to larger than the original.
编辑:Imagemagick使用Ghostscript渲染PDF文件.如果需要设置一些参数(例如分辨率以获得更好的图像),则可以直接使用Ghostscript.默认分辨率为72 DPI,这意味着A4纸的尺寸为595 x 841像素.使用150 DPI,您将获得两倍的像素数.例如
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
以上命令与Imagemagick使用的命令几乎相同.请注意-r参数,该参数设置150 DPI分辨率.您可以使用ImageMagick将生成的图像缩放到较小的尺寸.
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.
这篇关于如何在Linux服务器上用PDF文件创建缩略图/屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!