[模块] pdf转图片-pdf2image

可以转的库有:wand、PyMuPDF、pdf2image、PythonMagick

wand和PyMuPDF没找到二进制数据转图片的接口

PythonMagick没有测试成功

pdf2image转换速度很快,且支持二进制数据直接转图片,所以选择pdf2image

 

pdf2image需要poppler和pillow的支持

pip install pillow

windows下安装pippler:

下载地址:http://blog.alivate.com.au/poppler-windows/

然后将bin/文件夹添加到PATH

注意:配置之后需要重启一下电脑才会生效

centos下安装pippler:

yum install poppler poppler-cpp-devel poppler-utils

 

转换代码:

from pdf2image import convert_from_path,convert_from_bytes

# pdf的二进制数据转图片
images = convert_from_bytes(resp.content)
  for i, image in enumerate(images):
      image.save("第%d页.png" % i, "PNG")

 

# pdf文件转图片
images = convert_from_path(pdf_path)
for i, image in enumerate(images):
     image.save("第%d页.png" % i, "PNG")

 

参考:

https://blog.csdn.net/zbj18314469395/article/details/98329442

https://blog.51cto.com/11142243/2299706

posted @ 2020-01-19 13:38  Justaman  阅读(3534)  评论(0编辑  收藏  举报