UPDATE: Jspdf now support nodejs so should be able to import jspdf without having to add the browser globals as outlined in this answer.

You can actually use jspdf directly (npm install jspdf instead of npm install node-jspdf). Jspdf is currently (v1.3.2) not built with node support in mind, but you can mock the globals like below and get it to work that way. This is a basic example and all features of jspdf will not be available.

global.window = {document: {createElementNS: () => {return {}} }};
global.navigator = {};
global.html2pdf = {};
global.btoa = () => {};

var fs = require('fs');
var jsPDF = require('jspdf');

var doc = new jsPDF();
doc.text("Hello", 10, 10);
var data = doc.output();

fs.writeFileSync('./document.pdf', data, 'binary');

delete global.window;
delete global.html2pdf;
delete global.navigator;
delete global.btoa;
Answer from Simon Bengtsson on Stack Overflow
🌐
npm
npmjs.com › package › jspdf
jspdf - npm
PDF Document creation from JavaScript. Latest version: 3.0.4, last published: 17 days ago. Start using jspdf in your project by running `npm i jspdf`. There are 2036 other projects in the npm registry using jspdf.
      » npm install jspdf
    
Published   Nov 19, 2025
Version   3.0.4
🌐
npm
npmjs.com › package › jspdf-autotable
jspdf-autotable - npm
Generate pdf tables with javascript (jsPDF plugin). Latest version: 5.0.2, last published: 10 months ago. Start using jspdf-autotable in your project by running `npm i jspdf-autotable`. There are 477 other projects in the npm registry using jspdf-autotable.
      » npm install jspdf-autotable
    
Published   Feb 26, 2025
Version   5.0.2
Author   Simon Bengtsson
🌐
npm
npmjs.com › package › node-jspdf
node-jspdf - npm
Use jsPDF in your node apps.. Latest version: 0.0.3, last published: 11 years ago. Start using node-jspdf in your project by running `npm i node-jspdf`. There are no other projects in the npm registry using node-jspdf.
      » npm install node-jspdf
    
Published   Dec 15, 2014
Version   0.0.3
Author   jspdf.com, Calvin Froedge
🌐
GitHub
github.com › parallax › jsPDF
GitHub - parallax/jsPDF: Client-side JavaScript PDF generation for everyone.
jspdf.umd.*.js: UMD module format. For AMD or script-tag loading. polyfills*.js: Required polyfills for older browsers like Internet Explorer. The es variant simply imports all required polyfills from core-js, the umd variant is self-contained. Usually it is not necessary to specify the exact file in the import statement. Build tools or Node automatically figure out the right file, so importing "jspdf" is enough.
Starred by 30.9K users
Forked by 4.8K users
Languages   JavaScript 96.4% | TypeScript 2.4% | HTML 1.2%
🌐
GitHub
github.com › calvinfroedge › node-jspdf
GitHub - calvinfroedge/node-jspdf: jsPDF on the server.
var jsPDF = require('node-jspdf'); var doc = jsPDF(); doc.text(20, 20, 'Hello, world.'); doc.save('Test.pdf', function(err){console.log('saved!');});
Starred by 14 users
Forked by 18 users
Languages   JavaScript 72.9% | Shell 27.1%
🌐
APITemplate.io
apitemplate.io › home › how to generate a pdf with javascrip/node.js
How to Generate a PDF with JavaScrip/Node.js - APITemplate.io
October 13, 2024 - Ultimately, if you need extensive editing features, pdf-lib is the most capable option. For simple client-side PDF generation, html2pdf is user-friendly and effective. If you require high-quality outputs and server-side rendering, Puppeteer is the way to go, while jsPDF is lightweight and suitable for basic client-side use cases.
🌐
GitHub
github.com › parallax › jsPDF › issues › 2248
jsPDF Server Side node.js working solution · Issue #2248 · parallax/jsPDF
December 17, 2018 - I amended the code by doing dummy object declarations for the node env. global.window = {document: {createElementNS: () => {return {}} }}; global.navigator = {}; global.btoa = () => {}; const jsPDF = require('jspdf/dist/jspdf.node.debug') // Default export is a4 paper, portrait, using milimeters for units var doc = new jsPDF() doc.text('Hello world!', 10, 10) doc.save('a4.pdf')
Published   Jan 19, 2019
Find elsewhere
🌐
Parallax
parall.ax › products › jspdf
jsPDF
Generate professional PDFs easily with jsPDF, the open-source solution for PDF generation. Create event tickets, reports, certificates, and more in minutes with our intuitive interface.
🌐
jsDelivr
jsdelivr.com › package › npm › node-jspdf
node-jspdf CDN by jsDelivr - A CDN for npm and GitHub
December 15, 2014 - A free, fast, and reliable CDN for node-jspdf. Use jsPDF in your node apps.
Published   Nov 25, 2014
🌐
Tabnine
tabnine.com › home page › code › javascript › jspdf
jspdf.jsPDF JavaScript and Node.js code examples | Tabnine
let width = canvas.width / 8; let pdf = new jsPDF('p', 'mm', 'a4'); pdf.addImage(canvas.toDataURL('image/png'), 'PNG', 0, 0, width, height); let data = pdf.output(); fs.writeFileSync(filename, data, 'binary'); });
🌐
DEV Community
dev.to › xeshan6981 › the-5-nodejs-pdf-libraries-every-developer-must-know-4b39
The 5 Node.js PDF Libraries Every Developer Must Know - DEV Community
October 14, 2024 - jsPDF is a versatile JavaScript PDF library that can be used both in the browser and in Node.js.
🌐
jsPDF
artskydj.github.io › jsPDF › docs › index.html
jsPDF - GitHub Pages
The 14 standard fonts in PDF are limited to the ASCII-codepage. If you want to use UTF-8 you have to to integrate a custom font, which provides the needed glyphs. jsPDF supports .ttf-files. So if you want to have for example chinese text in your pdf, your font has to have the necessary chinese glyphs.
🌐
jsPDF
artskydj.github.io › jsPDF › docs › jsPDF.html
jsPDF - Documentation
Saves as PDF document. An alias of jsPDF.output('save', 'filename.pdf').
🌐
Templated
templated.io › blog › how-to-convert-html-to-pdf-with-nodejs
How To Convert HTML to PDF with Node.js
January 27, 2024 - This guide provides a step-by-step approach to converting HTML to PDF using Node.js, covering popular libraries like Puppeteer, jsPDF, and html-pdf.
🌐
APITemplate.io
apitemplate.io › home › convert html to pdf in node.js with 4 popular libraries (updated 2024)
Convert HTML to PDF in Node.js with 4 Popular Libraries (Updated 2024) - APITemplate.io
June 24, 2024 - jsPDF is a JavaScript library that allows you to generate PDF files from HTML programmatically. It works in both Node.js and browser environments.
🌐
RisingStack
blog.risingstack.com › home › hírek, események › puppeteer html to pdf generation with node.js
Puppeteer HTML to PDF Generation with Node.js - RisingStack Engineering
October 15, 2025 - import html2canvas from 'html2canvas' import jsPdf from 'jspdf' function printPDF () { const domElement = document.getElementById('your-id') html2canvas(domElement, { onclone: (document) => { document.getElementById('print-button').style.visibility = 'hidden' }}) .then((canvas) => { const img = canvas.toDataURL('image/png') const pdf = new jsPdf() pdf.addImage(imgData, 'JPEG', 0, 0, width, height) pdf.save('your-filename.pdf') })
🌐
GitHub
github.com › parallax › jsPDF › issues › 2805
jsPDF Server Side html() function generates empty pdf · Issue #2805 · parallax/jsPDF
March 1, 2020 - In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. ... global.window = {document: {createElementNS: () => {return {}} }}; global.navigator = {}; global.btoa = () => {}; const fs = require('fs') const html2canvas = require('html2canvas'); window.html2canvas = html2canvas; const jsPDF = require('jspdf/dist/jspdf.node.min') // Default export is a4 paper, portrait, using milimeters for units var doc = new jsPDF() doc.html('<p>Hello world!</p>'); fs.writeFileSync('./output.pdf', doc.output()) delete global.window; delete global.navigator; delete global.btoa;
Published   Jul 09, 2020
🌐
Medium
medium.com › deno-the-complete-reference › 5-useful-npm-packages-for-pdf-processing-in-node-js-c573cee51804
5 useful NPM packages for PDF processing in Node.js | Tech Tonic
December 9, 2024 - jsPDF is a popular and versatile JavaScript library designed to facilitate the creation of Portable Document Format (PDF) files from scratch or by merging existing documents. Developed by Nicolas J. Blatt, jsPDF offers a lightweight and easy-to-use ...
🌐
SurveyJS
surveyjs.io › pdf-generator › documentation › get-started-nodejs
Create PDF Forms in Node.js with SurveyJS
PDF Generator for SurveyJS allows you to generate interactive PDF forms on a Node.js server. This tutorial describes how to configure PDF form creation in a Node.js application. ... PDF Generator for SurveyJS is built upon the jsPDF library ...