Hi, I would like to know if it is expected when converting an A4 size PDF to PNG, the image is being generated as 596x842, as the A4 standard is 595x842.
For all tested resolutions, the width is 1 pixel larger.
72 dpi = 596x842
96 dpi = 795 x 1123
150 dpi = 1241 x 1754
300 dpi = 2481 x 3508
Code:
# For creating 300 DPI resolution images using PyMuPDF
DESIRED_INCREASE = 300/ 72
mat = fitz.Matrix(DESIRED_INCREASE, DESIRED_INCREASE)
doc = fitz.open(pdf_path)
for page in doc:
pix = page.getPixmap(matrix=mat)
pix.writePNG("page-%i.png" % page.number)
My settings:
Win10
Python 3.8
Image / pixmap dimensions of page images are created from page.rect.irect.
Because an A4 page is _not_ exactly 595 x 842, but something like Rect(0.0, 0.0, 595.3200073242188, 841.9199829101562), the IRect of that Rect is IRect(0, 0, 596, 842).
To see how IRect calculation works, consult the documentation of method Rect.bound(). These chapters are definitely worth reading, because not everything around emptiness, finiteness, containment and intersection of geometry objects always conforms with "intuition".
Maybe I should add that if indead a page's size has integer dimensions, then the pixmap will also have an IRect with these values.
Oh now I see, thanks for the explanation, and for the amazing work on this project!
Most helpful comment
Oh now I see, thanks for the explanation, and for the amazing work on this project!