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)
文章來源地址http://www.zghlxwxcb.cn/news/detail-784685.html
文章來源:http://www.zghlxwxcb.cn/news/detail-784685.html
到了這里,關(guān)于用python實(shí)現(xiàn)把PDF轉(zhuǎn)成圖片,測試成功轉(zhuǎn)化代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!