转换转转转化::::
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")