|
@@ -26,30 +26,41 @@ def findfiles(path):
|
|
|
|
|
|
def pyMuPDF_fitz(pdfPath, imagePath):
|
|
def pyMuPDF_fitz(pdfPath, imagePath):
|
|
global count
|
|
global count
|
|
- pdfDoc = fitz.open(pdfPath)
|
|
|
|
- cnt = 1
|
|
|
|
- for pg in range(pdfDoc.page_count):
|
|
|
|
- page = pdfDoc[pg]
|
|
|
|
- info = page.bound()
|
|
|
|
- radio = 0.0
|
|
|
|
- if info.width > info.height:
|
|
|
|
- radio = 800.0 / info.width
|
|
|
|
- else:
|
|
|
|
- radio = 800.0 / info.height
|
|
|
|
- rotate = int(0)
|
|
|
|
- zoom_x = 1.33333
|
|
|
|
- zoom_y = 1.333333
|
|
|
|
- mat = fitz.Matrix(zoom_x, zoom_y).prerotate(rotate)
|
|
|
|
- try:
|
|
|
|
- pix = page.get_pixmap(matrix=mat, alpha=False)
|
|
|
|
- except Exception as e:
|
|
|
|
- print("imagePath=" + pdfPath + " ---------------- ", e.__class__.__name__, e)
|
|
|
|
- continue
|
|
|
|
- if not os.path.exists(imagePath):
|
|
|
|
- os.makedirs(imagePath)
|
|
|
|
- pix.save(imagePath + '/' + str(pdfPath).split('\\')[-1][0:-4] + '-' + str(uuid.uuid1())[0:4] + '-' + str(cnt) + '.jpg')
|
|
|
|
- count += 1
|
|
|
|
- cnt += 1
|
|
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ pdfDoc = fitz.open(pdfPath)
|
|
|
|
+
|
|
|
|
+ cnt = 1
|
|
|
|
+ for pg in range(pdfDoc.page_count):
|
|
|
|
+ page = pdfDoc[pg]
|
|
|
|
+ info = page.bound()
|
|
|
|
+ radio = 0.0
|
|
|
|
+ if info.width > info.height:
|
|
|
|
+ radio = 800.0 / info.width
|
|
|
|
+ else:
|
|
|
|
+ radio = 800.0 / info.height
|
|
|
|
+ rotate = int(0)
|
|
|
|
+ zoom_x = 1.33333
|
|
|
|
+ zoom_y = 1.333333
|
|
|
|
+ mat = fitz.Matrix(zoom_x, zoom_y).prerotate(rotate)
|
|
|
|
+ try:
|
|
|
|
+ pix = page.get_pixmap(matrix=mat, alpha=False)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print("imagePath=" + pdfPath + " ---------------- ", e.__class__.__name__, e)
|
|
|
|
+ continue
|
|
|
|
+ if not os.path.exists(imagePath):
|
|
|
|
+ os.makedirs(imagePath)
|
|
|
|
+
|
|
|
|
+ file_name = os.path.splitext(os.path.basename(pdfPath))[0]
|
|
|
|
+ save_path = os.path.join(imagePath, file_name + '-' + str(uuid.uuid1())[0:4] + '-' + str(cnt) + '.jpg')
|
|
|
|
+ pix.save(save_path)
|
|
|
|
+ count += 1
|
|
|
|
+ cnt += 1
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(f"发生错误: {e}")
|
|
|
|
+
|
|
|
|
+ pdfDoc.close()
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|