A scheme for converting PDF files to PNG in Python

Currently the most reliable one is the Python binding based on mupdf: 
https://github.com/rk700/PyMuPDF 

demo address: 
https://github.com/rk700/PyMuPDF/blob/master/demo/demo.py

Installation:
Go to https://pypi.org/project/PyMuPDF/#files to download the installation file corresponding to the operating system. After the
download is complete, use pip to install
and then run the code.... The code to

convert the PDF file to PNG:

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)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324935200&siteId=291194637