pdf转图片
1. 安装 Release, 配置环境变量
Merge pull request #71 from Fdawgs/patch-1 Poppler 24.08.0
2. 安装 图片库
pip install pdf2image
3. 程序
from pdf2image import convert_from_path import os def pdf_to_images(pdf_path, output_folder, poppler_path): # 如果输出文件夹不存在,则创建它 if not os.path.exists(output_folder): os.makedirs(output_folder) # 将PDF文件转换为图像列表,指定poppler路径 images = convert_from_path(pdf_path, poppler_path=poppler_path) # 保存每个图像为一个文件 for i, image in enumerate(images): image_path = os.path.join(output_folder, f'page_{i + 1}.jpg') image.save(image_path, 'JPEG') if __name__ == "__main__": # PDF文件路径 pdf_file = "example.pdf" # 输出文件夹路径 output_dir = "output_images" # poppler可执行文件所在目录路径,根据你的实际安装路径修改 poppler_path = r"D:\迅雷下载\Release-24.08.0-0\poppler-24.08.0\Library\bin" pdf_to_images(pdf_file, output_dir, poppler_path)