import fitz PDF_path = "D:Users/FengZH2/Desktop/EM算法.pdf" imgs_save_path = "D:Users/FengZH2/Desktop/test/" def PDF_to_imgs(PDF_path, save_path): # 打开PDF文件,生成一个对象 doc = fitz.open(PDF_path) # 将PDF文件的每一页都转化为图片 for pg in range(doc.pageCount): page = doc[pg] rotate = int(0) # 每个尺寸的缩放系数为2,这将为我们生成分辨率提高4倍的图像。 zoom_x = 2 zoom_y = 2 trans = fitz.Matrix(zoom_x, zoom_y).preRotate(rotate) pm = page.getPixmap(matrix=trans, alpha=False) pm.writePNG(save_path + '%s.png' % pg) PDF_to_imgs(PDF_path, imgs_save_path)