JavaScript HTML to PDF libraries

Updated Nov 2026

JavaScript HTML to PDF libraries turn a web page or an HTML element into a PDF file. A headless browser prints the page with its print CSS, while an in-page converter draws the element onto a canvas or a PDF document. These libraries produce the receipts, statements, certificates, and archived web pages that apps save or send as PDFs.

Popularity

playwright-core has the most monthly downloads in this comparison, at 712.5M.

LibraryMonthly downloadsStarsLast releaseLicense
playwright-core
712.5M
100.4KNov 2026Apache-2.0
puppeteer-core
127.0M
95.8KNov 2026Apache-2.0
jspdf
83.5M
31.3KMar 2026MIT
electron
47.7M
124.0KNov 2026MIT
webdriverio
12.8M
9.9KNov 2026MIT
chrome-remote-interface
12.5M
4.6KFeb 2026MIT
selenium-webdriver
8.2M
34.6KNov 2026Apache-2.0
html2pdf.js
6.3M
4.9KJan 2026MIT
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Features compared

LibraryAccepts a DOM elementHTML header/footer templatesPage-range selection
playwright-coreUnsupportedBuilt-inBuilt-in
puppeteer-coreUnsupportedBuilt-inBuilt-in
jspdfBuilt-inUnsupportedUnsupported
electronUnsupportedBuilt-inBuilt-in
webdriverioUnsupportedUnsupportedBuilt-in
chrome-remote-interfaceUnsupportedBuilt-inBuilt-in
selenium-webdriverUnsupportedUnsupportedBuilt-in
html2pdf.jsBuilt-inUnsupportedUnsupported
Built-inNot supported

Libraries and code examples

playwright-core

Prints a browser page to PDF through page.pdf, using print CSS media.

Downloads / mo
712.5M
Stars
100.4K
Last release
1.65.1
License
Apache-2.0

Strengths

  • Header and footer templates. Set displayHeaderFooter with HTML templates for the print header and footer.

Limitations

  • PDF needs headless Chromium. Launch headless Chromium for PDF output, because other engines reject page.pdf.
  • Templates ignore page styles. Style header and footer templates inline, because page styles do not reach them.

Quickstart

From class-page
$ npm install playwright-core
import { chromium } from 'playwright-core';

const browser = await chromium.launch({ channel: 'chrome', headless: true });
const page = await browser.newPage();
await page.setContent('<h1>Hello</h1>');
await page.pdf({ path: 'output.pdf' });
await browser.close();

playwright-core examples

From open-source projects on GitHub

puppeteer-core

Provides the Puppeteer browser API without downloading Chrome during install.

Downloads / mo
127.0M
Stars
95.8K
Last release
25.18.1
License
Apache-2.0

Strengths

  • Honors CSS page sizes. Set preferCSSPageSize to use the page's CSS @page size over width, height, or format.
  • Fills header and footer values. Header templates fill in the date, title, URL, page number, and total pages.

Limitations

  • Backgrounds off by default. Set printBackground to true to keep background colors and images.
  • Needs a browser to connect to. Point puppeteer-core at an installed Chrome before launching.

Quickstart

From puppeteer.page.pdf
$ npm install puppeteer-core
import puppeteer from 'puppeteer-core';

const browser = await puppeteer.launch({ channel: 'chrome' });
const page = await browser.newPage();
await page.setContent('<h1>Hello</h1>');
await page.pdf({ path: 'output.pdf' });
await browser.close();

puppeteer-core examples

From open-source projects on GitHub

Provides an HTML-to-PDF method alongside programmable PDF document APIs.

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

Strengths

  • Matches supplied font faces. Pass fontFaces with font URLs when rendering HTML.
  • Fits HTML to target width. Set width and windowWidth together to fit the rendered element.

Limitations

  • HTML rendering adds dependencies. Load html2canvas and DOMPurify when rendering HTML strings.
  • Default paging can split text. Use text auto-paging for mostly single-column documents.

Quickstart

From module-html.html
$ npm install jspdf html2canvas dompurify
import { jsPDF } from 'jspdf';

const pdf = new jsPDF();
await pdf.html('<h1>Hello</h1>');
pdf.save('output.pdf');

jspdf examples

From open-source projects on GitHub

Builds desktop apps with JavaScript, HTML, and CSS.

Downloads / mo
47.7M
Stars
124.0K
Last release
45.4.1
License
MIT

Strengths

  • Prints a window's page. Call printToPDF on a window's webContents to print its loaded page.

Limitations

  • Backgrounds off by default. Set printBackground to true to include background graphics.

Quickstart

From app.md
$ npm install --save-dev electron
const { app, BrowserWindow } = require('electron');
const fs = require('node:fs/promises');

app.whenReady().then(async () => {
  const win = new BrowserWindow({ show: false });
  try {
    await win.loadURL('data:text/html,<h1>Hello</h1>');
    const pdf = await win.webContents.printToPDF({});
    await fs.writeFile('output.pdf', pdf);
  } finally {
    win.destroy();
    app.quit();
  }
});

electron examples

From open-source projects on GitHub

webdriverio

Automates browsers, and its savePDF command prints the current page to a PDF file.

Downloads / mo
12.8M
Stars
9.9K
Last release
10.2.0
License
MIT

Strengths

  • Returns the PDF bytes. savePDF writes the file and also returns its bytes as a Buffer.
  • Prints through WebDriver BiDi. BiDi sessions print from Chrome, Edge, and Firefox in headed or headless mode.

Limitations

  • File path must end in .pdf. Give savePDF a file path that ends in .pdf.

Quickstart

From index.ts
$ npm install webdriverio
import { remote } from 'webdriverio';

const browser = await remote({
  capabilities: { browserName: 'chrome', 'goog:chromeOptions': { args: ['--headless=new'] } }
});
try {
  await browser.url('data:text/html,<h1>Hello</h1>');
  await browser.savePDF('output.pdf');
} finally {
  await browser.deleteSession();
}

chrome-remote-interface

Sends Chrome DevTools Protocol commands and receives its events from JavaScript.

Downloads / mo
12.5M
Stars
4.6K
Last release
0.34.0
License
MIT

Strengths

  • Works with other protocol implementations. Connects to Chrome or another implementation of the DevTools Protocol.

Limitations

  • Needs a running browser. Start Chrome with a remote debugging port before connecting.

Quickstart

From README.md
$ npm install chrome-remote-interface
const CDP = require('chrome-remote-interface');
const fs = require('node:fs/promises');

(async () => {
  const client = await CDP();
  try {
    await client.Page.enable();
    const loaded = client.Page.loadEventFired();
    await client.Page.navigate({ url: 'data:text/html,<h1>Hello</h1>' });
    await loaded;
    const { data } = await client.Page.printToPDF({});
    await fs.writeFile('output.pdf', Buffer.from(data, 'base64'));
  } finally {
    await client.close();
  }
})();

chrome-remote-interface examples

From open-source projects on GitHub

selenium-webdriver

Provides the official Selenium WebDriver bindings, including a command that prints the page.

Downloads / mo
8.2M
Stars
34.6K
Last release
4.53.0
License
Apache-2.0

Strengths

  • Configurable print settings. Set page layout, margins, and scaling before printing.

Limitations

  • Returns encoded PDF data. Decode the returned string before writing it to a PDF file.

Quickstart

From webdriver.js
$ npm install selenium-webdriver
const { Builder } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const fs = require('node:fs/promises');

(async () => {
  const options = new chrome.Options().addArguments('--headless=new');
  const driver = await new Builder().forBrowser('chrome').setChromeOptions(options).build();
  try {
    await driver.get('data:text/html,<h1>Hello</h1>');
    await fs.writeFile('output.pdf', await driver.printPage({}), 'base64');
  } finally {
    await driver.quit();
  }
})();

Converts browser HTML elements into PDFs through html2canvas and jsPDF.

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

Strengths

  • Converts existing browser elements. Pass an existing page element into the conversion worker.
  • Controls element page breaks. Select page-break modes and selectors for splitting content.

Limitations

  • PDF text becomes an image. The resulting text cannot be selected or searched.
  • Large canvases can fail rendering. Keep rendered content within the browser’s canvas size limits.
  • Requires a browser. Run conversion in a browser rather than a Node-only process.

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

FAQ

A headless browser library such as puppeteer-core or playwright-core prints the page with its print CSS through page.pdf. Inside the browser, html2pdf.js and jsPDF convert an element on the page into a PDF.

jsPDF creates PDF documents from JavaScript, and its html method renders HTML into a document. Rendering HTML strings needs a canvas renderer and DOMPurify loaded alongside it.

Both print a page to PDF through page.pdf with print CSS media, and both accept HTML header and footer templates. Playwright generates PDFs only in headless Chromium. puppeteer-core skips the browser download and connects to an installed Chrome.

html2pdf.js converts an element on a web page into a PDF through a canvas renderer and jsPDF. Its PDFs hold an image of the content, and their text cannot be selected or searched. It runs only in a browser, not in Node.js.

Load the page, then call page.pdf to print it with print CSS media. Set printBackground to true to keep background graphics, and call emulateMediaType('screen') first to use screen styles.

No. Playwright generates PDFs only in headless Chromium, and other browser engines reject page.pdf.

For coding agents

Found your HTML to 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