Blazing fast, native PDF-to-image conversion for Node.js and Bun.
pdf-raster renders PDF pages into high-quality image buffers using a
high-performance Rust engine. Built with napi-rs and PDFium, it is
optimized for server-side workflows like OCR pipelines, VLM (Vision Language
Model) inputs, and document previews.
- π High Performance: 4xβ8x faster than
pdfjs-distcanvas-based implementations in the included local benchmark run. - π¦ Native Power: Leverages Rust and PDFium for industry-standard rendering.
- π οΈ Simple API: A single
convert()function handles everything. - π¦ Memory Efficient: Supports
Bufferinputs for processing without temp files. - π¨ Flexible Output: Native support for
png,jpeg, andwebp.
# Using Bun
bun add pdf-raster
# Using PNPM
pnpm add pdf-raster
# Using NPM
npm install pdf-rasterimport { convert } from "pdf-raster";
import { writeFile } from "node:fs/promises";
// Convert specific pages to high-quality WebP
const [page] = await convert("./report.pdf", {
pages: [0], // 0-indexed page numbers
dpi: 300, // Higher DPI is useful for OCR and VLM inputs
outputFormat: "webp",
});
console.log(`Rendered page ${page.pageIndex} (${page.width}x${page.height})`);
// page.data is a Buffer of the encoded image
await writeFile("output.webp", page.data);- Type:
string | Buffer | Uint8Array | ArrayBuffer - Description: A file path to a PDF or an in-memory PDF byte source.
| Option | Type | Default | Description |
|---|---|---|---|
pages |
number[] |
all |
Specific pages to render, using 0-indexed values. |
dpi |
number |
300 |
Resolution of the output image. |
outputFormat |
"png" | "jpeg" | "webp" |
"png" |
Encoding format for the returned buffers. |
password |
string |
- |
Password for encrypted PDFs. |
crop |
{ x, y, width, height } |
- |
Crop rectangle in rendered image pixel coordinates. |
renderAnnotations |
boolean |
true |
Whether to render annotations and form data. |
type ConvertedPage = {
pageIndex: number;
data: Buffer;
mimeType: "image/png" | "image/jpeg" | "image/webp";
width: number;
height: number;
dpi: number;
};Tested on Apple Silicon (M4). Results represent a local benchmark run
against the included fixture PDFs at 300 DPI.
| Library | Avg/Page | Relative Speed |
|---|---|---|
| pdf-raster | 0.86 ms | Baseline (Fastest) |
| pdfjs-dist + @napi-rs/canvas | 5.98 ms | ~6.9x slower |
| pdfjs-dist + node-canvas | 7.19 ms | ~8.4x slower |
Note
Benchmark results are based on the included local fixtures. Performance will
vary with PDF complexity and hardware. Run bun run benchmark on your own
machine to compare against your environment.
This package uses native bindings and is intended for server-side environments only.
| Runtime | Supported |
|---|---|
| Node.js | β Yes |
| Bun | β Yes |
| Browser | β No |
| Edge Runtimes | β No |
Supported Architectures:
- OS: Linux (gnu), macOS, Windows
- Arch: x64, arm64
Caution
Do not import this into browser bundles, React Client Components, or Vercel Edge Functions.
This repository is a Bun + Turborepo monorepo.
- Setup:
bun install - Native Binaries:
bun run pdfium:download - Build:
bun run build - Test:
bun run test - Benchmark:
bun run benchmark
core/- the publishedpdf-rasterpackageexample/- the polished internal demo app using the local workspace packageconsumer/- a minimal Next.js app for validating the published npm packagedocs/- the hosted documentation sourcebenchmark/- internal performance comparisons againstpdfjs-dist
MIT