DEV Community

Denny Guide
Denny Guide

Posted on

5 Ways to Turn PDF Pages Into PNG Images — I Benchmarked Them on a 20-Page Document

Every few weeks someone asks a variant of the same question: "how do I get these PDF pages
into PNG images?" — for slides thumbnails, for embedding pages in docs, for feeding pages
into an OCR model. There are a lot of answers, and most of them are slower than they need
to be.

I generated a synthetic 20-page PDF (US Letter, text + vector shapes) and ran the
contenders at 150 DPI on the same machine. Here's what I found.

The benchmark

Method 20 pages @150 DPI Throughput
macOS Preview / Acrobat (manual export) ~2 min of clicking —
pdftoppm (poppler) 4.1 s 4.8 pages/s
Ghostscript one-liner 0.9 s 21.2 pages/s
PyMuPDF (Python) 0.7 s 29.4 pages/s
Web converter upload-bound —

The spread surprised me: the "standard" poppler route is 6× slower than PyMuPDF on the
same document.

1. Preview / Acrobat — for one or two pages

Fine for a single page. Painful for 20. If you're exporting more than a handful of pages,
anything scripted below wins immediately.

2. pdftoppm — the default answer

pdftoppm -png -r 150 input.pdf page
# -> page-01.png, page-02.png, ...
Enter fullscreen mode Exit fullscreen mode

Preinstalled almost everywhere, dead simple, and slow — 4.1 s for 20 pages here. It's also
what the popular pdf2image Python package shells out to under the hood, so that package
inherits the same speed.

3. Ghostscript — the quiet workhorse

gs -q -dNOPAUSE -dBATCH -sDEVICE=png16m -r150 \
   -sOutputFile=page-%02d.png input.pdf
Enter fullscreen mode Exit fullscreen mode

One process renders every page (the %02d pattern handles numbering), at 21 pages/s.
Already installed on most servers.

4. PyMuPDF — the speed winner

import pymupdf

doc = pymupdf.open("input.pdf")
for i, page in enumerate(doc):
    pix = page.get_pixmap(matrix=pymupdf.Matrix(150 / 72, 150 / 72))  # 150 DPI
    pix.save(f"page-{i+1:02d}.png")
Enter fullscreen mode Exit fullscreen mode

29 pages/s, no subprocess overhead, and you control the DPI with a zoom matrix
(150/72 ≈ 2.08× — a 612×792 pt page becomes 1275×1650 px, ~187 KB per page here).
If you're doing anything programmatic — thumbnails, OCR preprocessing, page previews —
this is the one to pick.

5. A web converter — when you can't install anything

Locked-down work laptop, one-off task, or the PDF lives on your phone? Then a browser
tool is the pragmatic choice; I've used
iloveconvert.com's PDF to PNG converter
for exactly this — it bundles multi-page output and saves you the local setup entirely.

Takeaways

  1. For scripting: PyMuPDF, ~6× faster than the poppler default.
  2. For a server you already SSH into: the Ghostscript one-liner is already there.
  3. Save yourself the manual Preview export — anything past 2 pages isn't worth the clicks.

Top comments (0)