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 install pdf-lib
yarn add pdf-lib
pnpm add pdf-lib
Import
import { PDFDocument } from 'pdf-lib';Quick Example
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
| Package | pdf-lib |
| Category | File System |
| Weekly Downloads | 2M+ |
| License | MIT |
| Install | npm install pdf-lib |
Related Packages
Sharp is the highest-performance Node.js image processing library, using the libvips image processin…
Jimp (JavaScript Image Manipulation Program) is a pure JavaScript image processing library for Node.…
Archiver is a streaming interface for generating archive files (ZIP, TAR, TAR.GZ) in Node.js. The li…
fs-extra is a drop-in replacement for Node.js's built-in fs module that adds additional file system …
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.