1,安装pdf2image,pip3或者pycharm都可以
2,window安装配置poppler,[http://blog.alivate.com.au/poppler-windows/],然后将bin/文件夹放入PATH环境标量中。电脑重启,这样才会生效(这个很重要)
3,安装pillow,pip3或者pycharm都可以
import pdf2image
import os
from pdf2image import convert_from_path, convert_from_bytes
def pdf_img(pdfpath, imgpath):
“”“
方法一:
pdfpath:pdf的绝对路径
imgpath:要把图片放入的路径
注意2个目录均要存在
”“”
images = convert_from_path(pdfpath)
for img in images:
relimg_path = os.path.join(imgpath, '{}.jpg'.format(images.index(img)))
img.save(relimg_path)
# img.save(imgpath + '/' + '{}.jpg'.format(images.index(img)))
def pdf2(pdfpath, imgpath):
“”“
方法二
”“”
images = convert_from_bytes(open(pdfpath, 'rb').read())
for img in images:
relimg_path = os.path.join(imgpath, '{}.jpg'.format(images.index(img)))
img.save(relimg_path)
if __name__ == "__main__":
pdf2(r'C:UsersadminDesktop1636529634992.pdf',
r'C:UsersadminDesktoptest_covfpdf')
原文网址:
https://blog.csdn.net/zbj18314469395/article/details/98329442



