原文链接: https://www.oschina.net/question/3960741_2286489
1,这里使用的要先安装插件
pip install fitz
pip install pyMuPDF
2,这里是代码
zoom / 100.0 越大 合成的图片越清晰越大
import fitz
import glob
import time
def read_pdf(filename):
pdffile = glob.glob(filename)[0]
doc = fitz.open(pdffile)
new_time= int(round(time.time() * 1000))
for pg in range(0, 2): #这里也可以是 doc.pageCount
page = doc[pg]
zoom = int(1000)
rotate = int(0)
trans = fitz.Matrix(zoom / 100.0, zoom / 100.0).preRotate(rotate)
pm = page.getPixmap(matrix=trans, alpha=0) # alpha = 0
pm.writePNG(r'E:\testimgs\%s_%s.png' % (new_time,pg+1))
read_pdf('E:/mnln/python.pdf')
转换结果如下
来源:https://www.oschina.net/question/3960741_2286489