Skip to content

How to convert PDF to image, using the original document settings for the image size and set to 300dpi? #1307

Discussion options

You must be logged in to vote

Sounds like you will create a so-called "pixmap" for each page and save that as an image.
PyMuPDF itself only support a handful of image output formats, the most popular being PNG, others are the PNM-type images.
If you want to use others, you must use an additional package, presumably PIL/Pillow.
PyMuPDF supports Pillow directly via its pixmap output methods.
So a code snippet may look like this:

import fitz
mat = fitz.Matrix(300 / 72, 300 / 72)  # sets zoom factor for 300 dpi
doc = fitz.open("yourfile.pdf")
for page in doc:
    pix = page.get_pixmap(matrix=mat)
    img_filename = "page-%04i.tiff" % page.number
    pix.pil_save(img_filename, format="TIFF", dpi=(300,300), ... more PIL par…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@AddEleven
Comment options

@JorjMcKie
Comment options

Answer selected by AddEleven
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants