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.输出结果:

相关推荐
攻城狮7号14 分钟前
【第一节】Python爬虫基础-HTTP基本原理
爬虫·python·python爬虫
IT乐手15 分钟前
adb logcat 写文件乱码的解决方案
android·python
Python测试之道19 分钟前
Deepseek API+Python 测试用例一键生成与导出 V1.0.6(加入分块策略,返回更完整可靠)
开发语言·python·测试用例
SRC_BLUE_1722 分钟前
Python GUI 编程 | QObject 控件基类详解 — 定时器
开发语言·数据库·python
啊阿狸不会拉杆29 分钟前
第二十一章:Python-Plotly库实现数据动态可视化
开发语言·python·plotly
月走乂山37 分钟前
nocobase + Python爬虫实现数据可视化
爬虫·python·低代码·信息可视化
滴答滴答嗒嗒滴40 分钟前
Python小练习系列 Vol.12:学生信息排序(sorted + key函数)
开发语言·python
天天进步20151 小时前
Python项目-基于Flask的个人博客系统设计与实现(1)
开发语言·python·flask
安然无虞1 小时前
31天Python入门——第20天:魔法方法详解
开发语言·后端·爬虫·python
靠近彗星2 小时前
基于 Vue + Django + MySQL 实现个人博客/CMS系统
前端·vue.js·python·mysql·django