python批量转化pdf图片为jpg图片

1.把pdf图片批量转为jpg;需要注意的是,需要先安装poppler这个软件,具体安装教程放在下面代码中了

2.代码

python 复制代码
#poppler安装教程参考:https://blog.csdn.net/wy01415/article/details/110257130
#windows上poppler下载链接:https://github.com/oschwartz10612/poppler-windows
from pdf2image import convert_from_path
from PIL import Image
import os


def convert_pdf_to_jpg(pdf_folder, output_folder, poppler_path):
    for pdf_file in os.listdir(pdf_folder):
        if pdf_file.endswith('.pdf'):
            pdf_path = os.path.join(pdf_folder, pdf_file)
            images = convert_from_path(pdf_path, poppler_path=poppler_path)

            for i, image in enumerate(images):
                #如果pdf有多页用下面这个代码
                # output_filename = f"{os.path.splitext(pdf_file)[0]}_page_{i + 1}.jpg"
                # 如果pdf就1页用下面这个代码
                output_filename = f"{os.path.splitext(pdf_file)[0]}.jpg"
                output_path = os.path.join(output_folder, output_filename)

                image.save(output_path, 'JPEG')


pdf_folder = 'E:/pythonworking/file/pdf_merge/workspace'
output_folder = 'E:/pythonworking/file/pdf_merge/workspace'
poppler_path = 'D:/software/Poppler/Release-24.02.0-0/poppler-24.02.0/Library/bin'

convert_pdf_to_jpg(pdf_folder, output_folder, poppler_path)

3.输出结果:

相关推荐
Yorlen_Zhang3 小时前
Python Tkinter Text 控件完全指南:从基础编辑器到富文本应用
开发语言·python·c#
HAPPY酷3 小时前
C++ 和 Python 的“容器”对决:从万金油到核武器
开发语言·c++·python
gpfyyds6664 小时前
Python代码练习
开发语言·python
aiguangyuan5 小时前
使用LSTM进行情感分类:原理与实现剖析
人工智能·python·nlp
小小张说故事5 小时前
BeautifulSoup:Python网页解析的优雅利器
后端·爬虫·python
luoluoal5 小时前
基于python的医疗领域用户问答的意图识别算法研究(源码+文档)
python
Shi_haoliu5 小时前
python安装操作流程-FastAPI + PostgreSQL简单流程
python·postgresql·fastapi
ZH15455891315 小时前
Flutter for OpenHarmony Python学习助手实战:API接口开发的实现
python·学习·flutter
小宋10215 小时前
Java 项目结构 vs Python 项目结构:如何快速搭一个可跑项目
java·开发语言·python