imagemagick拆分大pdf到png的 [英] imagemagick splitting large pdf into png's

查看:117
本文介绍了imagemagick拆分大pdf到png的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个pdf文件,我想分割成单独的图片,每页都是一张图片,我正在使用以下imagemajick命令这样做:

I have a pdf I'd like to split into individual pictures, each page is a picture, I am using the following imagemajick command to do so:

convert -density 400 mypdf.pdf out.png

,它工作正常,但是我已经在pdf的前5页上对其进行了测试,并且花费了10秒的时间,以这种速度,大约需要半个小时才能拆分pdf,考虑到我我并没有真正做任何花哨的事情,我不是在旋转图像或以任何方式修改它们,我想知道是否有更快的方法来执行此操作.谢谢

and it works fine however I have tested it on the first 5 pages of my pdf and it took 10 seconds, at this rate it should take about half an hour to split my pdf, which seems strange to me considering that I'm not really doing anything fancy, I'm not rotating the images or modifying them in anyway, I'd like to know if there is a faster way to do this. Thanks

此外,我想保留质量,我以前是这样做的,没有密度标志,但是质量急剧下降.

Also, I'd like to preserve the quality, I was doing it before without the density flag but the quality dropped dramatically.

推荐答案

如果已安装Python,则应尝试PyMuPDF.它是MuPDF的Python绑定,非常易于使用且非常快(比xpdf快3倍).呈现PDF页面对于此程序包来说实在是一笔不小的开支.使用这样的脚本:

If you have Python installed, you should try PyMuPDF. It is a Python binding for MuPDF, extremely easy to use and extremely fast (3 times faster than xpdf). Rendering PDF pages is bread-and-butter business for this package. Use a script like this:

#----------------------------------------------------------------------------------
import fitz
fname = sys.argv[1]        # get filename from command line
doc = fitz.open(fname)     # open the file
mat = fitz.Matrix(2,2)     # controls resolution: scale factor in x and y direction
for page in doc:
    pix = page.getPixmap(matrix=mat, alpha=False)
    pix.writePNG("p-%i.png" % page.number) # write the page's image
#----------------------------------------------------------------------------------

矩阵"的更多内容:此表单将每个方向缩放2倍.因此,生成的PNG变为原始版本100%大小的默认版本的约4倍.两个尺寸都可以独立缩放.旋转或仅渲染页面的一部分也是可能的.

More to "Matrix": This form scales each direction by a factor of 2. So the resulting PNG becomes about 4 times larger than the default version in original, 100% size. Both dimensions can be scaled independently. Rotation or rendering only parts of a page is possible also.

有关PyMuPDF的更多信息:可作为Windows,OSX和PyPI的所有Linux版本的二进制轮使用.因此,安装仅需几秒钟的时间.Python部件的许可证是GNU GPL 3,MuPDF部件的许可证是GNU AFFERO GPL3.因此它是开源和免费的.不包括创建商业产品,但是您可以在相同的许可下自由分发.

More to PyMuPDF: Available as binary wheel for Windows, OSX and all Linux versions from PyPI. Installation therefore is a matter of a few seconds. The license for the Python part is GNU GPL 3, for the MuPDF part GNU AFFERO GPL 3. So it's open source and freeware. Creating commercial products is excluded, but you can freely distribute under the same licenses.

这篇关于imagemagick拆分大pdf到png的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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