pdf-lib
Create and modify PDF documents in JavaScript — works in Node.js, browsers, React Native, and Deno without any native dependencies.
pdf-lib
General JSCreate and modify PDF documents in JavaScript — works in Node.js, browsers, React Native, and Deno without any native dependencies.
Fit
Bundle (gzip)
177.5 kB
429.1 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Generating PDFs server-side traditionally requires headless Chrome (heavy) or server-only libraries. Client-side PDF creation (for download without a server round-trip) requires a pure JavaScript implementation.
What It Does
pdf-lib creates PDFs from scratch or modifies existing ones: embed custom fonts, draw text/images/shapes, fill form fields, merge documents, add pages, and set metadata. It runs in every JavaScript environment since it has zero native dependencies.
Installation
npm install pdf-libUsage Example
import { PDFDocument, rgb, StandardFonts } from 'pdf-lib';
const pdfDoc = await PDFDocument.create();
const page = pdfDoc.addPage([595, 842]); // A4
const font = await pdfDoc.embedFont(StandardFonts.Helvetica);
page.drawText('Invoice #1234', {
x: 50, y: 780,
size: 24,
font,
color: rgb(0, 0, 0),
});
page.drawLine({ start: { x: 50, y: 760 }, end: { x: 545, y: 760 }, thickness: 1 });
const pdfBytes = await pdfDoc.save();
// In Node.js:
await fs.writeFile('invoice.pdf', pdfBytes);
// In browser:
const blob = new Blob([pdfBytes], { type: 'application/pdf' });Related packages
Unified TypeScript SDK for building AI-powered apps — switch between 20+ LLM providers without rewriting code.
animejsGeneral JSLightweight JavaScript animation library with a tiny footprint and a powerful, expressive API.
AOSGeneral JSAn easy-to-use library that makes elements fade, slide, or zoom into view as the user scrolls down your page.
archiverGeneral JSStreaming interface for generating ZIP and TAR archives in Node.js — create compressed archives programmatically from files, directories, and buffers.
@formkit/auto-animateGeneral JS> Add smooth transitions to any element with a single line — zero-config animations for adds, removes, and moves.