import os import fitz def covert2pic(file_path, zoom, png_path): doc = fitz.open(file_path) total = doc.page_count for pg in range(total): page = doc[pg] zoom = int(zoom) # 值越大,分辨率越高,文件越清晰 rotate = int(0) trans = fitz.Matrix(zoom / 100.0, zoom / 100.0).prerotate(rotate) pm = page.get_pixmap(matrix=trans, alpha=False) if not os.path.exists(png_path): os.mkdir(png_path) save = os.path.join(png_path, '%s.png' %(pg+1)) pm.save(save) doc.close() if __name__ == "__main__": pdfPath = r'C:\Users\Thinkpad\Desktop\100\3证CE.pdf' imagePath = r'C:\Users\Thinkpad\Desktop\100\imgs' covert2pic(pdfPath, 200, imagePath)
文章来源地址https://www.toymoban.com/news/detail-784685.html
文章来源:https://www.toymoban.com/news/detail-784685.html
到了这里,关于用python实现把PDF转成图片,测试成功转化代码的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!