Referencing this answer (refrencing)

Just use await and make sure to return doc inside the callback

something like this

var doc = new jspdf.jsPDF({
  orientation: 'p',
  unit: 'pt',
  format: 'letter'
});


var field = "<b>html test </b>";
doc.text(10, 10, "test");
//add first html
await doc.html(field, {
  callback: function (doc) {
    return doc;
  },
  width: 210,
  windowWidth: 210, 
      html2canvas: {
          backgroundColor: 'lightyellow',
          width: 210, 
          height: 150
      },
      backgroundColor: 'lightblue', 
  x: 10,
  y: 50,
  autoPaging: 'text'
});
window.open(doc.output('bloburl'));

now you can call doc.html as many times as you want for that same document

Originally posted by @bakuur in https://github.com/parallax/jsPDF/issues/3074#issuecomment-1328427528

Answer from Baker Al-Nakib on Stack Overflow
🌐
jsPDF
artskydj.github.io › jsPDF › docs › jsPDF.html
jsPDF - Documentation
Saves as PDF document. An alias of jsPDF.output('save', 'filename.pdf').
Discussions

jspdf.html() doesn't render correctly
I'm just performing a simple jspdf.html() call but the rendered PDF does not match the rendered HTML. More on github.com
🌐 github.com
16
December 2, 2022
jsPDF.html output very large fields in document.
Hello there, i've been trying the jsPDF.html function, but it seems its outputting the html but in such large scale that it is unreadable. Am I doing something wrong? I've been using the li... More on github.com
🌐 github.com
20
August 28, 2020
🌐
JSFiddle
jsfiddle.net › onigetoc › 74gtwghw
Addhtml jsPDF - JSFiddle - Code Playground
The Code Completion will now also have the context of all panels before suggesting code to you - so if for example you have some CSS or JS, the HTML panel will suggest code based on the other two panels.
🌐
jsPDF
artskydj.github.io › jsPDF › docs › index.html
jsPDF - GitHub Pages
To add the font to jsPDF use our fontconverter in /fontconverter/fontconverter.html . The fontconverter will create a js-file with the content of the provided ttf-file as base64 encoded string and additional code for jsPDF. You just have to add this generated js-File to your project.
🌐
GeeksforGeeks
geeksforgeeks.org › html › how-to-generate-pdf-file-using-jspdf-library
Generate PDF File Using jsPDF Library - GeeksforGeeks
<html> <head> <style> body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f4f4f9; } .container { text-align: center; padding: 20px; background-color: #fff; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); } button { background-color: #4CAF50; color: white; border: none; padding: 10px 20px; font-size: 16px; cursor: pointer; border-radius: 5px; transition: background-color 0.3s; } button:hover { background-color: #45a049; } </style> </head> <body> <div class="container"> <h1>Generate PDF with jsPDF</h1> <button onclick="generatePDF()">Generate PDF</button> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script> </body> </html>
Published   July 23, 2025
🌐
CodePen
codepen.io › amkid › pen › qKYwXo
jsPDF from html
function getPDF() { var doc = new jsPDF(); // We'll make our own renderer to skip this editor var specialElementHandlers = { '#getPDF': function(element, renderer){ return true; }, '.controls': function(element, renderer){ return true; } }; // All units are in the set measurement for the document // This can be changed to "pt" (points), "mm" (Default), "cm", "in" doc.fromHTML($('.zima').get(0), 15, 15, { 'width': 170, 'elementHandlers': specialElementHandlers }); doc.save('Generated.pdf'); }
Find elsewhere
🌐
GitHub
github.com › parallax › jsPDF
GitHub - parallax/jsPDF: Client-side JavaScript PDF generation for everyone.
Client-side JavaScript PDF generation for everyone. - parallax/jsPDF
Starred by 30.9K users
Forked by 4.8K users
Languages   JavaScript 96.4% | TypeScript 2.4% | HTML 1.2%
🌐
C# Corner
c-sharpcorner.com › UploadFile › b629e0 › creating-pdf-from-html-through-jspdf
Creating PDF From HTML Using JSPDF
June 7, 2024 - JSPDF is an open-source library for generating PDF documents using nothing but JavaScript. It uses various functions to create various elements of PDF pages. ... Will print the string given in single quotes starting from the position given as ...
🌐
GitHub
github.com › parallax › jsPDF › issues › 3532
jspdf.html() doesn't render correctly · Issue #3532
December 2, 2022 - I am using Tailwind CSS in the HTML but I have also converted the Tailwind code into inlined styles which produces the exact same results. ... <div id="appGenPdfText" class="flex flex-col w-full h-full space-y-1"> <div class="flex flex-row bg-blue-200 justify-center"> <p class="m-1 text-primary text-xl">APPLICANT GENERAL INFORMATION</p> </div> <div class="flex bg-primary justify-center"> <p class="text-white">Primary Information</p> </div> </div> ... let pdf = await new jsPDF({ orientation: 'p', unit: 'pt', format: 'letter', putOnlyUsedFonts: true, compress: true }) const source = await document.getElementById('appGenPdfText') await pdf.html(source, { width: 580, windowWidth: 580, margin: 15 }) await pdf.save()
Published   Dec 02, 2022
🌐
GitHub
github.com › parallax › jsPDF › issues › 2885
jsPDF.html output very large fields in document. · Issue #2885 · parallax/jsPDF
August 28, 2020 - methods: { download() { var html = `<body> <h1>This is Title</h1> <div> <p>this is test no.1</p> </div> <div> <p><b>This is test no.1</b></p> </div> <div> <p>This is test no.3</p> </div> </body>`; var doc = new jspdf(); doc.html(html, { callback: function (doc) { doc.save(); }, }); }, },
Published   Aug 28, 2020
🌐
jsPDF
artskydj.github.io › jsPDF › docs › module-html.html
html - Documentation
Generate a PDF from an HTML element or string using. var doc = new jsPDF(); doc.html(document.body, { callback: function (doc) { doc.save(); } });
🌐
Pdfnoodle
pdfnoodle.com › blog › generating-pdfs-from-html-with-jspdf
Generating PDFs from HTML with jsPDF and javascript
January 30, 2025 - Learn how to convert HTML to PDF using jsPDF, a popular JavaScript library. Follow our step-by-step guide to generate professional PDFs from templates.
🌐
Decentro
decentro.tech › blog › engineering & apis › jspdf: what is it & how to use it to generate pdf from html
JsPDF: What Is It & How To Use It To Generate PDF from HTML - Decentro
June 12, 2024 - This makes it an ideal choice for developers who need a flexible and cost-effective solution for generating PDFs from their web applications. Today, we will use jsPDF to download an HTML file as a PDF, images, colors & backgrounds.
🌐
Phppot
phppot.com › javascript › html-to-pdf-in-javascript-using-jspdf
HTML to PDF in Javascript using jsPDF with Example Download - Phppot
December 3, 2022 - For example, it uses “dompurify” dependency to implement HTML to PDF conversion. The jsPDF is the best JavaScript library to create PDFs on the client-side. We have seen the jsPDF example already for converting HTML sources into PDF.
🌐
SitePoint
sitepoint.com › blog › javascript › generating pdfs from web pages on the fly with jspdf
Generating PDFs from Web Pages on the Fly with jsPDF — SitePoint
November 7, 2024 - Massimo Cassandro demonstrates how to make use of jsPDF, a JavaScript library for generating PDF documents from web pages.
🌐
DEV Community
dev.to › jringeisen › using-jspdf-html2canvas-and-vue-to-generate-pdfs-1f8l
Using jsPDF, html2Canvas, and Vue to generate PDF's. - DEV Community
October 29, 2021 - Now, once you've created your jsPDF object you'll need to use html2canvas to create an image which can then be converted to a pdf, like so:
🌐
findnerd
findnerd.com › list › view › Create-PDF-from-HTML-using-JSPDF › 28991
Create PDF from HTML using JSPDF
February 14, 2017 - Hello friends, welcome to findnerd. today i am going to tell you how to create pdf from html using jspdf. in this blog i am going to use fromhtml plugin to convert html page into pdf. copy and paste the following code into your file: fromhtml ex identify the parts you want to change if this is your first time editing a template, try not to get drawn into the idea of tweaking the colors and layout justyet. to do that you have to dig into css, the language responsible for page styling. its a good idea to focus on one thing at a time when youre new to template customization, and html is the best
🌐
OpenReplay
blog.openreplay.com › generating-a-pdf-from-a-div-using-the-jspdf-library
Generating a PDF from a div using the jsPDF Library
June 4, 2024 - jsPDF is a JavaScript library specifically built for client-side PDF generation. Its key features include: Client-side operation: Generates PDFs without server-side dependencies. Customization: Offers control over PDF layout, styling, and content.