pdf转图片,可以自由调节转换中的细节

        
转换转转转化::::

import os
import fitz  #此库为PyMuPDF中,采用版本为1.18.6
import time
pdf_path= r'path'
image_path= r'save_path'

def pdf2image(pdf_path,picturepath):
    pdfDoc = fitz.open(pdf_path)
    pictures=[]
    for page_num,page in enumerate(pdfDoc):
        width = page.rect.width
        height = page.rect.width
        multi = (width*height)/10000
        if multi<48:
            zoom_x=3
            zoom_y=3
            rotate = int(0)#不动
            mat= fitz.Matrix(zoom_x,zoom_y).preRotate(rotate)#是否旋转
            rect = page.rect
            x0 = rect.x0
            x1=rect.x1
            y0=rect.y0
            y1=rect.y1
            clip = fitz.Rect(x0,y0,x1,y1)#选定区域
            pix = page.getPixmap(matrix =mat,alpha = False ,clip = clip)#alpha决定是否保留图片透明度信息
            picture = os.path.join(picturepath,str(page_num)+'.png')
            pix.writePNG(picture)
            pictures.append(picture)
        elif multi>=48:
            zoom_x=3((48/multi)**0.5)
            zoom_y=3((48/multi)**0.5)
            rotate = int(0)
            mat= fitz.Matrix(zoom_x,zoom_y).preRotate(rotate)
            rect = page.rect
            x0 = rect.x0
            x1=rect.x1
            y0=rect.y0
            y1=rect.y1
            clip = fitz.Rect(x0,y0,x1,y1)
            pix = page.getPixmap(matrix =mat,alpha = False ,clip = clip)
            picture = os.path.join(picturepath,str(page_num)+'.png')
            pix.writePNG(picture)
            pictures.append(picture)
time_start =time.time()
pdf2image(pdf_path,image_path)
time_end=time.time()
print("耗时",time_end-time_start,"s")

        

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值