【python小工具】PDF转图片

PDF转图片

再也不需要使用wps收费啦~~

import os

from pdf2image import convert_from_path


def pdf_2_img():
    # pdf原始路径
    pdf_file_path = r'../test_data/纳税记录.pdf'
    # 转成图片的保存路径
    save_file_path = r'../test_data/纳税记录.jpg'
    if os.path.exists(save_file_path):
        return True
    print('开始转换pdf:%s' % pdf_file_path)
    try:
        # 转换为图像
        images = convert_from_path(pdf_file_path)
        images[0].save(save_file_path, 'JPEG')
        print('pdf转jpg完成')
    except Exception as e:
        print('PDF转图片出错: %s' % e)
        return None
    else:
        return True


pdf_2_img()

你可能感兴趣的:(python,pdf,开发语言)