pdf-raster

Benchmark

How pdf-raster compares with pdfjs-dist, how output size differs by format, and how to run the benchmark yourself.

The repository includes a benchmark that renders the same PDFs with pdf-raster and with pdfjs-dist on two Node.js canvas backends, @napi-rs/canvas and node-canvas.

text-20.pdf, 20 text pages
  • pdf-raster
    10.1 ms
  • pdfjs-dist + @napi-rs/canvas17.6× slower
    176.9 ms
  • pdfjs-dist + node-canvas25.5× slower
    256.9 ms
mixed-10.pdf, 10 pages of text and images
  • pdf-raster
    17.1 ms
  • pdfjs-dist + @napi-rs/canvas12.7× slower
    218.3 ms
  • pdfjs-dist + node-canvas17.5× slower
    299.1 ms

Milliseconds per page at 300 DPI to PNG, one conversion at a time, on an Apple M4 with 24 GB, macOS 27, Bun 1.4.2. Shorter is faster. Both charts share one scale.

One machine, two PDFs

All numbers on this page come from an Apple M4 (4 performance and 6 efficiency cores, 24 GB) on macOS 27, running the benchmark under Bun 1.4.2. Your hardware and your PDFs will give different numbers. Run the benchmark to measure them.

Run it

bun run benchmark

Flags:

  • --libs <list> picks which libraries to run, from pdf-raster, pdfjs-napi and pdfjs-node-canvas. All three run by default.
  • --output <format> sets the format, png, jpeg or webp.
  • --concurrency <n> starts n convert() calls at once and reports pages per second. It applies to pdf-raster only. The pdf.js backends always run one conversion at a time.
  • --dpi <n> and --pages <list> set the resolution and the zero-based pages to render.
  • --runs <n> and --warmups <n> set how many measured and warmup runs to do.
  • --json prints a JSON report instead of tables.

Pass PDF paths as arguments to benchmark your own files. The command runs inside benchmark/, so use absolute paths:

bun run benchmark -- /path/to/report.pdf --libs pdf-raster --output jpeg --concurrency 4

node-canvas needs system libraries

node-canvas builds against Cairo and other system libraries. Install its prerequisites first, or skip it with --libs pdf-raster,pdfjs-napi.

Fixtures and settings

The default fixtures are generated, letter-size PDFs written to benchmark/.fixtures/, which git ignores:

  • text-20.pdf has 20 pages of text.
  • mixed-10.pdf has 10 pages that alternate between text and a 1200 × 900 image.

bun run --cwd benchmark fixtures regenerates them. Each library renders at 300 DPI to PNG, with one warmup run followed by the measured runs.

Results

Output of bun run benchmark -- --runs 5 --warmups 1:

File: text-20.pdf (benchmark/.fixtures/text-20.pdf)
Settings: dpi=300, output=png, pages=all, warmups=1, runs=5, libs=pdf-raster,pdfjs-napi,pdfjs-node-canvas, concurrency=1
Input size: 112 KB
Library                       Pages  Avg total   P50 total   Avg/page   Pages/s  Avg bytes
----------------------------  -----  ----------  ----------  ---------  -------  ---------
pdf-raster                    20     201.52 ms   200.93 ms   10.08 ms   99.3     58.9 MB
pdfjs-dist + @napi-rs/canvas  20     3538.56 ms  3534.54 ms  176.93 ms  n/a      23.4 MB
pdfjs-dist + node-canvas      20     5137.57 ms  5136.13 ms  256.88 ms  n/a      30.1 MB

Relative speed (pdf-raster vs pdfjs-dist + @napi-rs/canvas): total 17.56x
Relative speed (pdf-raster vs pdfjs-dist + node-canvas): total 25.49x

File: mixed-10.pdf (benchmark/.fixtures/mixed-10.pdf)
Settings: dpi=300, output=png, pages=all, warmups=1, runs=5, libs=pdf-raster,pdfjs-napi,pdfjs-node-canvas, concurrency=1
Input size: 2.9 MB
Library                       Pages  Avg total   P50 total   Avg/page   Pages/s  Avg bytes
----------------------------  -----  ----------  ----------  ---------  -------  ---------
pdf-raster                    10     171.33 ms   170.26 ms   17.13 ms   58.4     52.9 MB
pdfjs-dist + @napi-rs/canvas  10     2182.96 ms  2184.32 ms  218.30 ms  n/a      19.4 MB
pdfjs-dist + node-canvas      10     2990.47 ms  2990.91 ms  299.05 ms  n/a      21.9 MB

Relative speed (pdf-raster vs pdfjs-dist + @napi-rs/canvas): total 12.74x
Relative speed (pdf-raster vs pdfjs-dist + node-canvas): total 17.45x

A relative speed of 17.56x means the other library took 17.56 times as long as pdf-raster for the whole run.

If a library fails on a PDF, the benchmark prints a skipped: line with the error and continues with the others.

Output size

Avg bytes is the total output of one run. pdf-raster compresses PNGs with a fast setting, so its PNG files are about 2.5 times larger than the ones pdfjs-dist writes. For the 20 pages of text-20.pdf, that is 58.9 MB against 23.4 MB.

Average size per page from pdf-raster at 300 DPI:

Formattext-20mixed-10
PNG3016 KB5414 KB
WebP (lossless)965 KB2345 KB
JPEG (quality 75)1228 KB1124 KB

WebP gives the smallest lossless output. On text pages it also beats JPEG. On pages with photos, JPEG is the smallest.

Throughput and concurrency

Pages per second from pdf-raster at 300 DPI, with 1 and 4 convert() calls running at once:

FormatCallstext-20mixed-10
PNG197.458.4
PNG4105.866.2
JPEG159.747.7
JPEG467.456.3
WebP196.157.8
WebP4102.365.0

Extra calls add 6 to 18 percent, because PDFium renders one page at a time across the whole process. They help most with JPEG, where encoding takes a larger share of each page. PNG and WebP encode at almost the same speed.

Compared with 0.1.0

The published pdf-raster@0.1.0 on the same machine, text-20.pdf, one call at a time, timed with the same settings (one warmup, five runs):

Format0.1.0, pages/s0.2.0, pages/sChange
PNG28.397.43.4×
JPEG14.159.74.2×
WebP36.896.12.6×

JPEG moved to a faster encoder, and pages now encode in parallel outside the PDFium lock. Concurrency and memory explains the model.

What the numbers do and do not show

The benchmark measures end-to-end convert() time on two synthetic PDFs. Use it to compare libraries on your hardware and to catch regressions between versions. It does not predict the speed of every PDF. Pages with complex vector art, many fonts or large images render slower.

On this page