JavaScript PDF libraries

Updated Nov 2026

JavaScript PDF libraries create PDF files, and some also modify existing PDFs.

jsPDF, PDFKit, pdfmake, and @react-pdf/renderer generate new documents from drawing calls, a document definition, or React components. pdf-lib, its fork @cantoo/pdf-lib, and LibPDF load an existing PDF to fill its forms, copy its pages, or add content. html2pdf.js turns a rendered web page into a PDF inside the browser. These libraries produce the invoices, tickets, and reports that apps generate for download.

Popularity

pdf-lib has the most monthly downloads in this comparison, at 103.5M.

LibraryMonthly downloadsStarsLast releaseLicense
pdf-lib
118.0M
8.7KNov 2021MIT
jsPDF
83.5M
31.3KMar 2026MIT
PDFKit
64.5M
10.7KAug 2026MIT
@react-pdf/renderer
36.3M
16.9KAug 2026MIT
pdfmake
17.0M
12.4KNov 2026MIT
@cantoo/pdf-lib
13.1M
361Sep 2026MIT
html2pdf.js
6.3M
4.9KJan 2026MIT
LibPDF
1.2M
1.9KOct 2026MIT
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

pdf-lib creates new PDFs and modifies existing ones, and runs in Node.js, browsers, Deno, and React Native. A loaded document can gain, lose, or reorder pages, copy pages from another PDF, and take new text, images, and SVG paths. The form API creates fields, fills them, and flattens them into page content. Custom fonts embed once the separate @pdf-lib/fontkit package is registered. Encrypted PDFs are outside its support.

Downloads / mo
118.0M
Stars
8.7K
Last release
1.17.1
License
MIT

Strengths

  • Modifies existing PDF documents. Load existing PDFs to add content, copy pages, and update form fields.
  • Creates and fills PDF forms. Create fields or read and fill existing text fields and controls.

Limitations

  • Page text editing is restricted. Existing page text can't be edited or removed; only form field text changes.
  • Needs unencrypted input PDFs. Encrypted PDFs must be decrypted before loading and modifying them.
  • Custom fonts need fontkit. Install and register @pdf-lib/fontkit before embedding custom fonts.

Quickstart

From README.md
$ npm install --save pdf-lib
import {PDFDocument} from 'pdf-lib'

const pdfDoc = await PDFDocument.create()
const page = pdfDoc.addPage()
page.drawText('Hello world!', {x: 50, y: 700, size: 20})
const pdfBytes = await pdfDoc.save()

pdf-lib examples

From open-source projects on GitHub

jsPDF generates PDF documents from drawing commands in the browser or Node.js. new jsPDF() starts a portrait page measured in millimeters, doc.text places a string at a position, and doc.save writes the file, as a download in the browser and to disk in Node.js. Options set the paper size, orientation, and unit. The html method converts an HTML element into PDF content, and a bundled table API turns rows of data into a table.

Downloads / mo
83.5M
Stars
31.3K
Last release
4.2.1
License
MIT

Strengths

  • Creates tables without extras. Use the bundled table API to turn structured data into a table.
  • Downloads generated PDFs. Use save() to download a generated PDF in the browser.

Limitations

  • Cannot parse existing PDFs. Generate new documents; use another library to modify an existing PDF.
  • HTML conversion needs extra packages. HTML conversion requires html2canvas, plus DOMPurify when passing an HTML string.
  • Unicode needs a custom font. Characters outside the standard fonts need an embedded TrueType font.

Quickstart

From README.md
$ npm install jspdf
import { jsPDF } from "jspdf";

// Default export is a4 paper, portrait, using millimeters for units
const doc = new jsPDF();

doc.text("Hello world!", 10, 10);
doc.save("a4.pdf");

jsPDF examples

From open-source projects on GitHub

PDFKit generates multi-page PDFs in Node.js and the browser through a chainable API. A PDFDocument streams its output, so a file or an HTTP response receives the PDF as it is written. Drawing calls follow the HTML canvas API, and text wraps across lines with alignment and bulleted lists. Fonts embed with subsetting from TrueType, OpenType, and WOFF files. Documents can also carry tables, annotations, form fields, outlines, encryption, and the tagged structure that accessible PDFs use.

Downloads / mo
64.5M
Stars
10.7K
Last release
0.20.2
License
MIT

Strengths

  • Streams generated documents. Pipe PDF output to a file or HTTP response as it is written.
  • Includes table generation. Add tables with native methods for rows, columns, and display options.
  • Creates interactive PDF forms. Add text fields, selection controls, buttons, and form actions.

Limitations

  • Browser builds need font registration. Register standard font metrics before creating a browser document with default Helvetica.
  • Browser file paths need registration. Load font and image bytes before using paths in the browser.

Quickstart

From getting_started.html
$ npm install pdfkit
const PDFDocument = require('pdfkit');
const fs = require('fs');
const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));
doc.text('Hello world!');
doc.end();

PDFKit examples

From open-source projects on GitHub

@react-pdf/renderer

@react-pdf/renderer builds PDFs from React components, in the browser and on the server. A document is written with Document, Page, View, and Text components and styled through StyleSheet.create with CSS-like properties such as flex direction and margin. In the browser, PDFViewer shows the result in the page. On the server, ReactPDF.render writes it to a file. The package only creates PDFs, and the separate react-pdf package displays existing ones.

Downloads / mo
36.3M
Stars
16.9K
Last release
4.9.0
License
MIT

Quickstart

From README.md
$ yarn add @react-pdf/renderer
import React from 'react';
import ReactPDF, {Document, Page, Text} from '@react-pdf/renderer';

const MyDocument = () => (
  <Document><Page size="A4"><Text>Hello world!</Text></Page></Document>
);
ReactPDF.render(<MyDocument />, './example.pdf');

@react-pdf/renderer examples

From open-source projects on GitHub

pdfmake builds PDFs from a document definition, a JavaScript object that lists content and styles, in Node.js and browsers. The library works out the layout: line wrapping, lists, columns, and tables with column and row spans and header rows that repeat after a page break. Definitions also set page headers and footers, a table of contents, watermarks, and QR codes. createPdf turns a definition into a file that downloads, opens, or prints in the browser.

Downloads / mo
17.0M
Stars
12.4K
Last release
0.3.14
License
MIT

Strengths

  • Uses declarative page layouts. Describe paragraphs, tables, and styles instead of calculating text coordinates.
  • Handles merged table cells. Build tables with headers, borders and cells spanning rows or columns.

Limitations

  • Fillable forms remain unsupported. Use another library when the PDF needs interactive form fields.
  • HTML needs a separate converter. Convert HTML into document definitions with a separate adapter.

Quickstart

From client-side docs
$ npm install pdfmake
import pdfMake from 'pdfmake/build/pdfmake';
import pdfFonts from 'pdfmake/build/vfs_fonts';
pdfMake.addVirtualFileSystem(pdfFonts);
pdfMake.createPdf({ content: 'Hello world!' }).download('document.pdf');

pdfmake examples

From open-source projects on GitHub

@cantoo/pdf-lib

@cantoo/pdf-lib is a maintained fork of pdf-lib that keeps the original API and adds features the original lacks. It draws full SVG images rather than only SVG paths, and extractContents pulls text and images out of a page. Incremental updates append changes without rewriting the whole file, which signing workflows depend on. The fork also recovers truncated PDFs that the original rejects.

Downloads / mo
13.1M
Stars
361
Last release
2.11.1
License
MIT

Quickstart

From README.md
$ npm install @cantoo/pdf-lib
import { PDFDocument } from '@cantoo/pdf-lib';
const doc = await PDFDocument.create();
const page = doc.addPage();
page.drawText('Hello world!', { x: 50, y: 700 });
const bytes = await doc.save();

@cantoo/pdf-lib examples

From open-source projects on GitHub

html2pdf.js converts a web page or a single element into a PDF entirely in the browser. It draws the element onto a canvas with html2canvas and places the resulting image into a document with jsPDF. One chained call takes the element and saves the file, and options set margins, page size, image quality, and page breaks. Text in the output is part of the image.

Downloads / mo
6.3M
Stars
4.9K
Last release
0.14.0
License
MIT

Limitations

  • Browser only. The library needs a browser and won't run in Node.js.

Quickstart

From README.md
$ npm install html2pdf.js
import html2pdf from 'html2pdf.js';
const element = document.getElementById('element-to-print');
html2pdf(element);

html2pdf.js examples

From open-source projects on GitHub

LibPDF is a TypeScript library that parses, modifies, and generates PDFs, with a parser that falls back gracefully on malformed files. It fills and flattens forms, merges and splits documents, extracts text with positions, and embeds fonts with subsetting. Encryption, digital signatures, and incremental saves that keep existing signatures valid are built in. Documenso, the company that wrote it, runs it in production, and the project labels itself beta software.

Downloads / mo
1.2M
Stars
1.9K
Last release
0.5.3
License
MIT

Limitations

  • Beta software. APIs may change between minor versions.

Quickstart

From README.md
$ npm install @libpdf/core
import { PDF } from "@libpdf/core";

const pdf = await PDF.load(bytes);
const pages = pdf.getPages();

console.log(`${pages.length} pages`);

LibPDF examples

From open-source projects on GitHub

FAQ

To generate a PDF from code, use jsPDF for drawing calls or pdfmake for a declarative layout with tables. To change an existing PDF or fill its forms, use pdf-lib. In a React app, use @react-pdf/renderer to build the document from components.

jsPDF generates PDFs from drawing commands in the browser and Node.js. It creates new documents only, and changing an existing PDF takes another library such as pdf-lib.

pdf-lib creates and modifies PDF documents in Node.js, browsers, Deno, and React Native. It edits existing files, fills and flattens forms, copies pages between documents, and embeds images and fonts.

pdfmake generates PDFs in Node.js and browsers from a declarative document definition. The definition lists paragraphs, tables, and styles, and pdfmake works out line wrapping, page breaks, and repeated table headers.

With jsPDF, create a document with new jsPDF(), add text with doc.text, and call doc.save to download or write the file. pdfmake takes a document definition object instead and builds the layout from it.

html2pdf.js converts a page or element in the browser by drawing it onto a canvas with html2canvas and placing the image into a PDF with jsPDF. The html method in jsPDF does the same through html2canvas.

For coding agents

Found your PDF library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official