pdf转图片-不支持中文路径

-- 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)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容