Python pdf 转 图片

安装依赖

D:\OpenSource\Python>pip install pdf2image pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
from pdf2image import convert_from_path
from PIL import Image


def pdf_to_image(pdf_path, output_path):
    # 将PDF文件转换为图像列表
    images = convert_from_path(pdf_path)

    # 遍历图像列表并保存到指定路径
    for i, image in enumerate(images):
        image.save(output_path + "/output_{0}.png".format(i))

    # 调用函数,将PDF转换为图像


pdf_to_image(r"D:\Users\Desktop\1\20231026-100524.pdf", r"D:\Users\Desktop\1\images")


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章