Menu

Why the same A4 page at 300 DPI is 2480 or 2481 pixels wide depending on the tool
📰

Why the same A4 page at 300 DPI is 2480 or 2481 pixels wide depending on the tool

DEV Community: javascript·NullPointerZen·10 days ago
#9KfrWpvH
#devtojavascript#devto#dev#pdftoppm#tool
Reading 0:00
15s threshold

Ask two PDF converters for the same A4 page at 300 DPI and one hands back a PNG 2481 pixels wide while the other says 2480. Nothing is broken, and a calculator is enough to see why. I ran one A4 page (595.276 × 841.89 pt, generated by me) through four things on a single Apple M4 machine, once each: poppler's pdftoppm 26.08.0, PyMuPDF 1.26.5, pdf.js 4.4.168 in a desktop Chromium 149, and ImgIng, a PDF to image tool in the desktop browser at https://imging.ai/ with its three presets of 144, 216 and 300 DPI. In the runs I watched, ImgIng sent no request that carried the file.

Four tools, three answers

A4 at 300 DPI Width × height

pdftoppm 2481 × 3508

PyMuPDF 2481 × 3508

pdf.js, canvas sized with Math.floor 2480 × 3507

ImgIng, 300 DPI preset 2480 × 3508

The pdf.js row is partly my doing. pdf.js hands you a viewport with fractional sizes, and the floor comes from my own line that creates the canvas.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.