1、安装pdf2image包
pip install pdf2image
2、安装popper,这是一个pdf2image需要的支持组件
在本文上面下载
下载解压后,将bin设置到windows的PATH环境变量
3、编写python程序
def pdf_to_jpg(pdf_path_filename):
# 获取pdf_path中路径部分
jpg_path = os.path.split(pdf_path_filename)[0]
filename = os.path.split(pdf_path_filename)[1].split('.')[0]
print(pdf_path_filename)
pages = convert_from_path(pdf_path_filename, 150)
if not os.path.exists(jpg_path):
os.makedirs(jpg_path)
for i, page in enumerate(pages):
print(1,filename)
filename = create_filename(filename, i)
print(2,filename)
page.save(jpg_path + "/" + filename + '.jpg', 'JPEG')
# open the folder
os.startfile(jpg_path)