API Reference
@scaryterry/pdfium
@scaryterry/pdfium
Section titled “@scaryterry/pdfium”@scaryterry/pdfium is a TypeScript PDF platform built on Google PDFium.
It has two public surfaces:
- Core API (
@scaryterry/pdfium) for PDF read/write/render workflows in Node.js and browsers. - React viewer toolkit (
@scaryterry/pdfium/react) for production viewer UIs (provider, viewer, toolbar, hooks, panels).
Who This Is For
Section titled “Who This Is For”- Teams building backend or frontend PDF workflows with one API.
- Teams that need a ready viewer, but still want low-level control when needed.
- Teams that want Node.js and browser support without switching libraries.
This project is not only a raw WASM wrapper and not only a viewer. It is both.
Install
Section titled “Install”pnpm add @scaryterry/pdfiumIf you use React components, also install peer dependencies:
pnpm add react react-dom lucide-reactChoose Your Entry Point
Section titled “Choose Your Entry Point”import { PDFium } from '@scaryterry/pdfium'for core document/page APIs.import { PDFiumProvider, PDFViewer } from '@scaryterry/pdfium/react'for React UI.import '@scaryterry/pdfium/worker'for worker entry modules.import wasmUrl from '@scaryterry/pdfium/pdfium.wasm?url'(bundlers that support asset URLs).
If you only need programmatic PDF processing, start with the core API. If you need a viewer UI quickly, start with the React toolkit.
Quick Start (Core API)
Section titled “Quick Start (Core API)”import { PDFium } from '@scaryterry/pdfium';import { readFile } from 'node:fs/promises';
const pdfBytes = await readFile('document.pdf');
using pdfium = await PDFium.init();using doc = await pdfium.openDocument(pdfBytes);using page = doc.getPage(0);
console.log('pages:', doc.pageCount);console.log('first page text length:', page.getText().length);
const rendered = page.render({ scale: 2 });console.log('rgba bytes:', rendered.data.length, 'size:', rendered.width, 'x', rendered.height);Quick Start (React Viewer)
Section titled “Quick Start (React Viewer)”Create an app worker entry:
import '@scaryterry/pdfium/worker';Then wire provider + viewer:
import wasmUrl from '@scaryterry/pdfium/pdfium.wasm?url';import { PDFiumProvider, PDFViewer } from '@scaryterry/pdfium/react';
const workerUrl = new URL('./pdfium.worker.ts', import.meta.url).toString();
export function App({ pdfBytes }: { pdfBytes: ArrayBuffer }) { return ( <PDFiumProvider wasmUrl={wasmUrl} workerUrl={workerUrl} initialDocument={{ data: pdfBytes, name: 'document.pdf' }} > <div style={{ height: '100vh' }}> <PDFViewer /> </div> </PDFiumProvider> );}Verify in 60 Seconds
Section titled “Verify in 60 Seconds”- Core path:
PDFium.init()succeeds and you can open a document. - React path:
PDFiumProvidermounts with validworkerUrlandwasmUrl/wasmBinary. - Rendering path: first page renders to RGBA or the viewer shows page 1.
Runtime Requirements
Section titled “Runtime Requirements”- Node.js:
>=22 - Browsers: modern browsers with
WebAssembly,Worker, andArrayBuffer - Module format: ESM
WASM/Worker Rules
Section titled “WASM/Worker Rules”- Node core API:
PDFium.init()works directly (WASM auto-load). - Browser core API: provide
wasmUrlorwasmBinary. - React provider: provide
workerUrland (wasmUrlorwasmBinary).
Optional Native Backend (Node.js)
Section titled “Optional Native Backend (Node.js)”For faster Node workloads, install a platform package and request native mode:
import { PDFium } from '@scaryterry/pdfium';
const pdfium = await PDFium.init({ useNative: true });Platform packages:
pnpm add @scaryterry/pdfium-darwin-arm64pnpm add @scaryterry/pdfium-darwin-x64pnpm add @scaryterry/pdfium-linux-x64-gnupnpm add @scaryterry/pdfium-linux-arm64-gnupnpm add @scaryterry/pdfium-win32-x64-msvcDocumentation
Section titled “Documentation”- Docs site: https://jacquesg.github.io/pdfium/
- Introduction: https://jacquesg.github.io/pdfium/
- Installation: https://jacquesg.github.io/pdfium/installation/
- React docs: https://jacquesg.github.io/pdfium/react/
- API reference: https://jacquesg.github.io/pdfium/api/
- Docs voice guide:
docs/DOCS_VOICE_GUIDE.md
License
Section titled “License”MIT