pdf转图片(利用pdf2image包)

参考: pdf2image

python 复制代码
pip install pdf2image

代码:

python 复制代码
from pdf2image import convert_from_path, convert_from_bytes
import os

output_folder = './xx/'
dpi_value= 600
pdf_start_page = 1 # pdf显示的第一页
start_page = 1 # 真实页码
prex = '' # 图像前缀

def to_image():
    def page_generator():# 定义图像前缀
        while True:
            yield prex
    images = convert_from_path(r'xx.pdf', dpi=600, output_folder=output_folder,
                               first_page=pdf_start_page, fmt='jpg', thread_count=6, output_file=page_generator())
   


 
def image_rename():
    # 文件重命名
    global start_page
    file_list = os.listdir(output_folder)
    for file in file_list:
        start_page_str =  str(start_page)
        if len(start_page_str)==1:
            start_page_str = '00'+start_page_str
        elif len(start_page_str)==2:
            start_page_str = '0'+start_page_str
        else:
            ...
        path = os.path.join(output_folder, file)
        print(os.path.join(output_folder, start_page_str + '.jpg'))
        os.rename(path, os.path.join(output_folder, start_page_str + '.jpg'))
        start_page = start_page + 1
to_image()
image_rename() #文件重命名

效果:非常快

相关推荐
Less is moree5 分钟前
PDF无法打印怎么解决?
pdf
lijun_xiao20095 小时前
Python-将身份证正反面图片-生成PDF
pdf
A尘埃6 小时前
项目七:PDF智能公式与计算(金融机构信贷报告自动解析与风险评估)
pdf
百事牛科技18 小时前
PDF如何设置密码?3种方法保护文件安全
windows·pdf
mysusheng18 小时前
2025 批量下载微博内容/图片/视频,导出word和pdf,微博点赞/评论/转发等数据导出excel
pdf·word·excel
lijun_xiao200918 小时前
Python-PDF文件生成水印
pdf
zongxingfengyun18 小时前
图片转pdf接口
pdf
cpych18 小时前
如何从 PDF 中删除页面
pdf
开开心心就好1 天前
无需函数:Excel数据筛选工具推荐
xml·网络·pdf·华为云·word·excel·音视频
拓端研究室2 天前
专题:2025构建全自动驾驶汽车生态系统:中国智能驾驶行业全景研究报告|附80+份报告PDF、数据仪表盘汇总下载
pdf·自动驾驶·汽车