1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import datetime import os
import fitz
def pyMuPDF_fitz(pdfPath, imagePath): startTime_pdf2img = datetime.datetime.now()
print("imagePath=" + imagePath) pdfDoc = fitz.open(pdfPath) for pg in range(pdfDoc.page_count): 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.get_pixmap(matrix=mat, alpha=False)
if not os.path.exists(imagePath): os.makedirs(imagePath)
pix.save(imagePath + '/' + 'images_%s.png' % pg)
endTime_pdf2img = datetime.datetime.now() print('pdf2img时间=', (endTime_pdf2img - startTime_pdf2img).seconds)
if __name__ == "__main__": pdfPath = './pdfs/shegong274.pdf' imagePath = 'images' pyMuPDF_fitz(pdfPath, imagePath)
|