-- coding: UTF-8 --
pip install PyMuPDF
import datetime
import os
import fitz
def Pdf_img(pdfPath,imagePath):
startTime =datetime.datetime.now()
dirName = os.path.basename(pdfPath).split('.')[0]
imagePath =imagePath+'\'+dirName
print('imagePath='+imagePath)
pdfDoc = fitz.open(pdfPath)
dirName = os.path.basename(pdfPath).split('.')[0]
for pg in range(pdfDoc.pageCount):
page = pdfDoc[pg]
rotate = int(0)
zoom_x = 1.33333333
zoom_y = 1.33333333
mat =fitz.Matrix(zoom_x,zoom_y).preRotate(rotate)
pix = page.getPixmap(matrix=mat,alpha=False)
if not os.path.exists(imagePath):
os.makedirs(imagePath)
pix.writePNG(imagePath+'/'+dirName+'images_%s.png'%pg)
ennTime = datetime.datetime.now()
print('执行时间:',(ennTime-startTime).seconds)
def listDir(filePath,imagePath):
files = os.listdir(filePath)
for file in files:
if file.split('.')[1] == 'pdf':
pdfPath= filePath+'\\'+file
print(pdfPath)
Pdf_img(pdfPath,imagePath)
if name =='main':
filePath = r'D:\test\26'
imagePath = r'D:\test'
#Pdf_img(pdfPath, imagePath)
listDir(filePath,imagePath)