Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to convert pdf to png by python

Shulou Source: shulou.com Published: 2022-06-02 06:47:28 11月13日 Update

This article mainly explains "how python realizes pdf to png". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "Python how to realize pdf to PNG"!

Dependency module pip install pympdf ==1.18.9 conversion code import fitzdef pdf2img(pdf_path, zoom_x, zoom_y):doc = fitz.open (pdf_path) #Open document for page in doc: #Traverse pages pix = page.get_pixmap(matrix=fitz.Matrix(zoom_x, zoom_y)) #Render pages as images pix.writePNG(f'main-{page. png +1}.png') #Store images as PNG format doc.close() #Close document if __name__number = "___":pdf2img("xxx.pdf", zoom_x=3, zoom_y=3)

pdf_path: path of pdf document to be converted

zoom_x: Scale factor of matrix in x direction

zoom_y: scaling factor of matrix in y direction

Note: Zoom_x and zoom_y generally take the same value, the larger the value, the higher the image resolution. (For more details on matrix parameters, see here)

quoting reference

https://pymupdf.readthedocs.io/en/latest/faq.html#how-to-make-images-from-document-pages

At this point, I believe that everyone has a deeper understanding of "how to realize pdf to png in python", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Tags: Document matrix content parameters image direction coefficient page learning practical deeper same code interest resolution picture practical practical easy to operate Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia MySQL Microsoft Apple