Jae*_*ess 47 python pdf jpeg imagemagick python-imaging-library
我正在尝试使用Python将多页PDF转换为一系列JPEG.我可以使用可用的工具轻松地将PDF分割成单独的页面,但我无法找到任何可以将PDF转换为图像的内容.
PIL不起作用,因为它无法读取PDF.我发现的两个选项是通过shell使用GhostScript或ImageMagick.这对我来说不是一个可行的选择,因为这个程序需要跨平台,我不能确定这些程序中是否有任何一个可以安装和使用它们.
有没有可以做到这一点的Python库?
Ada*_*eld 20
小智 7
这里有什么用我使用python ghostscript模块(由'$ pip install ghostscript'安装):
import ghostscript
def pdf2jpeg(pdf_input_path, jpeg_output_path):
args = ["pdf2jpeg", # actual value doesn't matter
"-dNOPAUSE",
"-sDEVICE=jpeg",
"-r144",
"-sOutputFile=" + jpeg_output_path,
pdf_input_path]
ghostscript.Ghostscript(*args)
Run Code Online (Sandbox Code Playgroud)
我还在我的电脑上安装了Ghostscript 9.18,否则它可能不会起作用.