Introduction
@scaryterry/pdfium is a TypeScript PDF platform built on Google PDFium.
It serves two primary use cases:
- Core document API (
@scaryterry/pdfium) for read/write/render/search workflows. - React viewer toolkit (
@scaryterry/pdfium/react) for shipping a full viewer UI quickly.
What You Get
Section titled “What You Get”- Typed PDF primitives and high-level document/page APIs.
- Cross-runtime support for Node.js and browsers.
- Worker-capable runtime model for off-main-thread processing.
- Optional native Node backend for higher throughput.
- React components/hooks for viewer composition (
PDFiumProvider,PDFViewer, panels, toolbar).
Who Should Start Here
Section titled “Who Should Start Here”- You want to pick the correct API surface before writing code.
- You need to understand WASM and worker setup rules up front.
- You are deciding between direct core API usage and viewer composition.
Runtime Model (Important)
Section titled “Runtime Model (Important)”- Node.js core API:
PDFium.init()works directly. - Browser core API: pass
wasmUrlorwasmBinary. - React viewer: pass
workerUrland (wasmUrlorwasmBinary) toPDFiumProvider.
If you skip those browser/React inputs, initialization cannot complete.
Choose Your Path
Section titled “Choose Your Path”Path A: Core API
Section titled “Path A: Core API”Use this path when you want programmatic PDF workflows:
- render pages to RGBA
- extract/search text
- inspect annotations/bookmarks/attachments
- create and modify PDFs
Start here:
Path B: React Viewer Toolkit
Section titled “Path B: React Viewer Toolkit”Use this path when you want a production viewer UI:
- plug-and-play
PDFViewer - customizable toolbar and side panels
- headless hooks for custom layouts
Start here:
Minimal Examples
Section titled “Minimal Examples”Core API
Section titled “Core API”import { PDFium } from '@scaryterry/pdfium';
using pdfium = await PDFium.init();using document = await pdfium.openDocument(pdfBytes);using page = document.getPage(0);
const text = page.getText();const image = page.render({ scale: 2 });console.log(text.length, image.width, image.height);React Viewer
Section titled “React 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();
function App() { return ( <PDFiumProvider wasmUrl={wasmUrl} workerUrl={workerUrl} initialDocument={{ data: pdfBytes, name: 'sample.pdf' }}> <PDFViewer /> </PDFiumProvider> );}Next Steps
Section titled “Next Steps”- Installation for bundler/asset setup.
- Quick Start for end-to-end core API setup.
- React for worker + WASM setup and viewer architecture.
- API Reference for full type and method reference.