Quick Start
Use this page when you want a first successful run before diving into the full guides.
What You Will Build
Section titled “What You Will Build”- A Node.js script that opens a PDF and renders page 1.
- A clear understanding of what changes in browser and React environments.
1. Install
Section titled “1. Install”pnpm add @scaryterry/pdfiumIf you are building a React viewer, also install React peers:
pnpm add react react-dom lucide-react2. Run a Core API Script (Node.js)
Section titled “2. Run a Core API Script (Node.js)”Create quick-start.ts:
import { readFile } from 'node:fs/promises';import { PDFium } from '@scaryterry/pdfium';
async function main() { const pdfBytes = await readFile('document.pdf');
using pdfium = await PDFium.init(); using document = await pdfium.openDocument(pdfBytes); using page = document.getPage(0);
console.log('Page count:', document.pageCount); console.log('First page text length:', page.getText().length);
const { width, height, data } = page.render({ scale: 2 }); console.log('Rendered image:', width, 'x', height, 'RGBA bytes:', data.length);}
main().catch((error) => { console.error(error); process.exit(1);});Run it:
npx tsx quick-start.ts3. Understand the Runtime Differences
Section titled “3. Understand the Runtime Differences”- Node core API: no extra WASM path setup needed.
- Browser core API: pass
wasmUrlorwasmBinaryintoPDFium.init(...). - React viewer: pass
workerUrland (wasmUrlorwasmBinary) intoPDFiumProvider.
4. Browser Core API Example
Section titled “4. Browser Core API Example”import { PDFium } from '@scaryterry/pdfium';
const wasmBinary = await fetch('/pdfium.wasm').then((r) => r.arrayBuffer());using pdfium = await PDFium.init({ wasmBinary });using doc = await pdfium.openDocument(pdfArrayBuffer);console.log(doc.pageCount);5. React Viewer Next
Section titled “5. React Viewer Next”React setup always requires worker + WASM wiring. Start with:
- React overview
- Installation for exact worker/asset wiring
Verify
Section titled “Verify”Your quick start is healthy if:
Page count:prints a number.Rendered image:prints width/height and RGBA byte length.- No
INIT_WASM_*or worker timeout errors appear.
Resource Management Reminder
Section titled “Resource Management Reminder”Most objects implement Symbol.dispose. Prefer using:
using page = document.getPage(0);If you do not use using, call dispose() manually.