目前最靠譜的是基於 mupdf 的 Python 綁定:
https://github.com/rk700/PyMuPDF
demo地址:
https://github.com/rk700/PyMuPDF/blob/master/demo/demo.py
安裝:
到 https://pypi.org/project/PyMuPDF/#files 下載操做系統對應的安裝文件
下載完成後,使用pip安裝
而後就能夠跑代碼了....
將PDF文件轉換成PNG的代碼:git
import fitz import sys doc = fitz.open('demo.pdf') for pg in range(doc.pageCount): page = doc[pg] zoom = int(100) rotate = int(0) trans = fitz.Matrix(zoom / 100.0, zoom / 100.0).preRotate(rotate) # create raster image of page (non-transparent) pm = page.getPixmap(matrix=trans, alpha=False) # write a PNG image of the page pm.writePNG('%s.png' % pg)