pdf转图片

pip install PyMuPDF

import fitz
def pdf_image(pdfPath, imgPath, zoom_x, zoom_y, rotation_angle):
    # 打开PDF文件
    pdf = fitz.open(pdfPath)
    # 逐页读取PDF
    for pg in range(0, pdf.page_count):
        page = pdf[pg]
        # 设置缩放和旋转系数
        trans = fitz.Matrix(zoom_x, zoom_y).prerotate(rotation_angle)
        pm = page.get_pixmap(matrix=trans, alpha=False)
        # 开始写图像
        pm._writeIMG(imgPath + str(pg) + ".png",1,1)
    pdf.close()

pdf_image(r"fsyy-en-cn.pdf", r"images/", 10, 10, 0)   

posted on 2024-01-30 11:15  耀扬  阅读(7)  评论(0编辑  收藏  举报

导航