Node.js 24+ · Bun · PDFium

Render PDF pages to PNG, JPEG and WebP.

pdf-raster runs PDFium in a native addon written in Rust. Pass convert() a path or a Buffer and get back one encoded image per page.

$ npm install pdf-raster
report.pdfpage 1 of 12
image/png · 2550 × 3300300 dpi
per page at 300 DPI to PNG on a 20-page text PDF
10.1 ms
faster than pdfjs-dist with @napi-rs/canvas on the same PDF
17.6×
prebuilt targets, macOS, Linux and Windows on x64 and arm64
6
the most raw pages held in memory at once, across all calls
8 frames

API

One function that returns an image per page

convert(input, options?) takes a file path, Buffer, Uint8Array or ArrayBuffer. It resolves to an array with one entry per page, holding the encoded bytes, the MIME type and the pixel size.

convert.ts
import { writeFile } from "node:fs/promises";
import { convert } from "pdf-raster";

const pages = await convert("./report.pdf", {
  pages: [0, 1],
  dpi: 300,
  outputFormat: "webp",
});

for (const page of pages) {
  await writeFile(`page-${page.pageIndex + 1}.webp`, page.data);
}
Resolved value
[
  {
    pageIndex: 0,
    data: <Buffer 52 49 46 46 ...>,
    mimeType: "image/webp",
    width: 2550,
    height: 3300,
    dpi: 300,
  },
  // one entry per requested page
]
ConvertOptionsAPI reference →
OptionTypeDefault
pagesnumber[]all pages
dpinumber300
outputFormat"png" | "jpeg" | "webp""png"
passwordstring
crop{ x, y, width, height }
renderAnnotationsbooleantrue
maxPixelsnumberunlimited

Benchmark

12.7× to 17.6× faster than pdf.js on a canvas

The repository benchmark renders two generated letter-size PDFs at 300 DPI and compares pdf-raster with pdfjs-dist on two Node.js canvas backends.

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.

pdf-raster writes PNGs with fast compression, so its PNG files are about 2.5 times larger than the ones pdfjs-dist produces. WebP is also lossless, encodes almost as fast, and is about a third of the PNG size on text pages.

These numbers come from one machine. Run bun run benchmark in the repository to measure your own hardware and PDFs. Benchmark details

Concurrency

Safe to call from many requests at once

PDFium is not thread-safe, so pdf-raster renders one page at a time behind a process-wide lock. Encoding happens outside the lock, so other calls can render while earlier pages encode.

  1. 01

    Input

    path, Buffer, Uint8Array or ArrayBuffer

  2. 02locked

    Render

    PDFium, one page at a time behind a process-wide lock

  3. 03parallel

    Encode

    PNG, JPEG or WebP on up to 4 threads per call

  4. 04

    Result

    ConvertedPage[] with bytes, size and DPI

  • At most 8 rendered pages exist at once in the process. At 300 DPI on letter paper that is about 270 MB.
  • Set maxPixels when clients choose the DPI. Oversized pages fail with INVALID_OPTIONS before any memory is allocated. Concurrency and memory

Use cases

Where pdf-raster fits

It renders pages and stops there. Pass the buffers to whatever comes next.

pdf-raster does not run in browsers, Edge runtimes or WebAssembly, and it does not edit PDFs or extract text.

Convert your first PDF

The quickstart covers file paths, buffers, page selection and output formats in a few short examples.

MIT license. Rendering by PDFium, bindings by napi-rs.pdf-raster