Skip to content

jsPDF

A JavaScript library that creates PDF files in the browser or in Node.js.

Stars
31.3k
Forks
4.8k
Licence
MIT
Language
JavaScript
Last update
4 days ago
Type
Library

What it is

jsPDF is a JavaScript library for generating PDF documents from code. You create a document object, add text and other content, then save or download the file. It runs client-side in browsers and can also run in Node.js, where it saves files to disk.

  • Generate a one-page A4 document with a line of text and save it as a file
  • Create a landscape document with custom page dimensions in inches
  • Produce PDFs from a Node.js script that writes to the current working directory
  • Embed a custom TrueType font to render UTF-8 text such as Chinese characters

Great for

  • Web developers who need to let users download a generated PDF from a page
  • Node.js developers who want to write PDF files from a script
  • Teams building invoices, reports, or certificates from data in their app
  • Developers who want to avoid a server-side PDF service

Not ideal for

  • People who need to edit or fill existing PDF files, since the README only describes generating new documents
  • Non-developers looking for a ready-made PDF tool, because it is a code library with no interface
  • Projects needing non-Latin text without extra work, since the README says standard PDF fonts are limited to ASCII and custom .ttf fonts must be added for UTF-8
Step-by-step guide: how to use jsPDFInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js or a browser with a script tag (Node version not stated in the README)

    Install from npm

    npm install jspdf --save

    Or install with yarn

    yarn add jspdf
  2. 2

    Run it

    • Install jspdf with npm or yarn, or add the unpkg script tag to an HTML page
    • Import the library with import { jsPDF } from "jspdf";
    • Create a document with const doc = new jsPDF();
    • Add text with doc.text("Hello world!", 10, 10);
    • Save it with doc.save("a4.pdf");
  3. 3

    Get the most out of it

    • Set page size, orientation, and units through the constructor options (orientation, unit, format)
    • Add a custom .ttf font with the fontconverter or addFileToVFS and addFont to show UTF-8 text
    • In Node.js, use Node's --permission and --allow-fs-read flags to control file access
    • Mark unused optional dependencies such as html2canvas as webpack externals to reduce bundle size
    • Check the Documentation site for the full API

Downloads

Strengths

  • Installs from npm and works with common build tools and module formats (ES, UMD, Node)
  • Has a live demo and documentation site linked from the README
  • Widely used, with 31,317 stars and an MIT license

Trade-offs

  • The README warns that user input should be sanitized before being passed to jsPDF
  • Advanced features depend on choosing the right API mode, and some plugins only work in compat mode
  • Optional features such as the html method need extra dependencies like html2canvas

How it compares

ProjectStarsTypeLevelUpdatedBest for
jsPDF (this)31.3kLibrarybeginner4 days agoWeb developers who need to let users download a generated PDF from a page
pdfkit10.7kLibrarybeginner4 days agoNode.js developers who need to generate PDFs such as invoices or reports from application data

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.