Python有多种方式将pdf文件转为图片,最简单的是使用pdf2image。
安装相应软件
sudo apt-get install poppler-utils
pip install pdf2image
直接运行
from pdf2image import convert_from_path, convert_from_bytes
import os,sys
import tempfile
from pdf2image.exceptions import (
PDFInfoNotInstalledError,
PDFPageCountError,
PDFSyntaxError
)
with tempfile.TemporaryDirectory() as path:
images_from_path = convert_from_path('./data/普通高等学校本科专业目录.pdf', dpi=300,fmt='jpg', output_folder='./data/pic')
此缺点是无法指定输出的文件名,但文件名的最后部分有_01数字进行标识。