📂
File System2M+/wkMIT

pdf-lib

pdf-lib is a library for creating and modifying PDF documents in any JavaScript environment, working in Node.js, browsers, Deno, and React Native without native

Installation

npm
npm install pdf-lib
yarn
yarn add pdf-lib
pnpm
pnpm add pdf-lib

Import

ESM
import { PDFDocument } from 'pdf-lib';

Quick Example

usage
import { PDFDocument, rgb } from 'pdf-lib';

const pdfDoc = await PDFDocument.create();
const page = pdfDoc.addPage([600, 400]);

page.drawText('Hello World!', {
  x: 50,
  y: 350,
  size: 30,
  color: rgb(0, 0.2, 0.8),
});

const pdfBytes = await pdfDoc.save();

About pdf-lib

pdf-lib is a library for creating and modifying PDF documents in any JavaScript environment, working in Node.js, browsers, Deno, and React Native without native dependencies. Unlike many PDF libraries that only generate PDFs from scratch, pdf-lib can load existing PDFs, modify them (add pages, draw text and images, fill forms, merge documents), and save the results. The library supports creating new PDFs with custom page sizes, drawing text with standard and custom fonts (embedding .ttf and .otf fonts), drawing images (PNG, JPEG), drawing shapes (rectangles, circles, lines, SVG paths), adding form fields, setting document metadata, and encrypting PDFs. pdf-lib handles PDF form operations including filling text fields, checking checkboxes, selecting radio buttons, and setting dropdown values — making it ideal for automated document generation and form processing. The library is written in TypeScript with no dependencies, keeping bundle sizes small for browser usage. pdf-lib provides low-level access to PDF operators for advanced use cases and supports PDF specification features including annotations, bookmarks, and page labels. The library is the most popular choice for client-side PDF manipulation in web applications.

Quick Facts

Packagepdf-lib
CategoryFile System
Weekly Downloads2M+
LicenseMIT
Installnpm install pdf-lib

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.