Installation
Install LibPDF for Node.js, Bun, or browsers.
Installation
Package Managers
npm install @libpdf/corepnpm add @libpdf/coreyarn add @libpdf/corebun add @libpdf/coreRequirements
- Node.js 18 or later
- Bun 1.0 or later
- TypeScript 5+ (recommended, but not required)
- ESM only - CommonJS is not supported
Browser Usage
LibPDF works in browsers with any modern bundler:
- Vite
- webpack
- esbuild
- Rollup
No Node.js polyfills are required. The library uses Uint8Array for binary data, which is natively supported in all modern browsers.
// Works the same in browsers
import { PDF } from "@libpdf/core";
const response = await fetch("/document.pdf");
const bytes = new Uint8Array(await response.arrayBuffer());
const pdf = await PDF.load(bytes);TypeScript Configuration
If you're using TypeScript, ensure your tsconfig.json has the following settings:
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler",
"esModuleInterop": true
}
}Verify Installation
Create a simple script to verify everything is working:
import { PDF } from "@libpdf/core";
const pdf = PDF.create();
pdf.addPage();
const bytes = await pdf.save();
console.log(`Created PDF with ${bytes.length} bytes`);Run it:
npx tsx verify.ts
# or with Bun
bun run verify.tsYou should see output like Created PDF with 1234 bytes.
