Introduction
pdf-raster renders PDF pages to PNG, JPEG or WebP buffers in Node.js and Bun.
pdf-raster turns PDF pages into encoded images on the server. It runs PDFium,
the PDF engine from Chromium, inside a native addon written in Rust with
napi-rs. You call one function, convert(), and get back one image buffer per
page.
import { convert } from "pdf-raster";
const pages = await convert("./report.pdf");
// pages[0].data is a PNG Buffer of the first page- 01
Input
path, Buffer, Uint8Array or ArrayBuffer
- 02locked
Render
PDFium, one page at a time behind a process-wide lock
- 03parallel
Encode
PNG, JPEG or WebP on up to 4 threads per call
- 04
Result
ConvertedPage[] with bytes, size and DPI
When to use it
Use pdf-raster when the next step in your system needs page images instead of PDF bytes. For example:
- OCR engines such as Tesseract.js
- vision models that accept image input
- page previews and thumbnails in a web app
- batch jobs that store or index documents as images
What it does not do
- It does not run in browsers, Edge runtimes or WebAssembly. It needs Node.js 24 or newer, or Bun.
- It does not edit PDFs, fill forms or extract text.
Output
Each page comes back as a ConvertedPage:
type ConvertedPage = {
pageIndex: number; // zero-based index in the source PDF
data: Buffer; // the encoded image
mimeType: "image/png" | "image/jpeg" | "image/webp";
width: number; // pixels
height: number; // pixels
dpi: number;
};The extra fields describe data, so you can store, serve or forward the bytes
without decoding the image first.