Skip to content

Quick Start

Use this page when you want a first successful run before diving into the full guides.

  • A Node.js script that opens a PDF and renders page 1.
  • A clear understanding of what changes in browser and React environments.
Terminal window
pnpm add @scaryterry/pdfium

If you are building a React viewer, also install React peers:

Terminal window
pnpm add react react-dom lucide-react

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:

Terminal window
npx tsx quick-start.ts
  • Node core API: no extra WASM path setup needed.
  • Browser core API: pass wasmUrl or wasmBinary into PDFium.init(...).
  • React viewer: pass workerUrl and (wasmUrl or wasmBinary) into PDFiumProvider.
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);

React setup always requires worker + WASM wiring. Start with:

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.

Most objects implement Symbol.dispose. Prefer using:

using page = document.getPage(0);

If you do not use using, call dispose() manually.