在Windows上预览PDF的JPEG? [英] Get a preview JPEG of a PDF on Windows?

查看:119
本文介绍了在Windows上预览PDF的JPEG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个跨平台(Python)应用程序需要生成PDF的第一页的JPEG预览。

I have a cross-platform (Python) application which needs to generate a JPEG preview of the first page of a PDF.

在Mac上我正在产生< a href =http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/sips.1.html\"rel =noreferrer>啜饮。我能在Windows上做些类似的事吗?

On the Mac I am spawning sips. Is there something similarly simple I can do on Windows?

推荐答案

ImageMagick无论如何都将PDF->位图转换委托给GhostScript,所以这里是您可以使用的命令(它基于ImageMagick中 ps:alpha 委托列出的实际命令,只是调整为使用JPEG作为输出):

ImageMagick delegates the PDF->bitmap conversion to GhostScript anyway, so here's a command you can use (it's based on the actual command listed by the ps:alpha delegate in ImageMagick, just adjusted to use JPEG as output):

gs -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT \
-dMaxBitmap=500000000 -dLastPage=1 -dAlignToPixels=0 -dGridFitTT=0 \
-sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r72x72 \
-sOutputFile=$OUTPUT -f$INPUT

其中 $ OUTPUT $ INPUT 是输出和输入文件名。将 72x72 调整为您需要的任何分辨率。 (显然,如果你将整个命令写成一行,则去除反斜杠。)

where $OUTPUT and $INPUT are the output and input filenames. Adjust the 72x72 to whatever resolution you need. (Obviously, strip out the backslashes if you're writing out the whole command as one line.)

这有两个原因:


  1. 您不再需要安装ImageMagick。并不是说我有任何反对ImageMagick的东西(我喜欢它),但我相信简单的解决方案。

  2. ImageMagick进行两步转换。首先是PDF-> PPM,然后是PPM-> JPEG。这样,转换是一步。

需要考虑的其他事项:对于我测试的文件,PNG压缩比JPEG。如果您想使用PNG,请将 -sDEVICE = jpeg 更改为 -sDEVICE = png16m

Other things to consider: with the files I've tested, PNG compresses better than JPEG. If you want to use PNG, change the -sDEVICE=jpeg to -sDEVICE=png16m.

这篇关于在Windows上预览PDF的JPEG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆