今天有个需求要把pdf的图片导出,我搜了一下好像百度不出来啥,都是在线的工具或者收费的,于是google了一下,招到了git上面的这个项目
安装python模块&软件
需要python3环境
pip3 install pdf2image
yum install -y poppler-utils
python代码
from pdf2image import convert_from_path, convert_from_bytes
import tempfile
from pdf2image.exceptions import (
PDFInfoNotInstalledError,
PDFPageCountError,
PDFSyntaxError
)
with tempfile.TemporaryDirectory() as path:
images_from_path = convert_from_path('/home/test.pdf', fmt='PNG',output_folder='/home')
运行&结果
自己导出即可
github项目地址:https://github.com/Belval/pdf2image