jsPDF is able to use plugins. In order to enable it to print HTML, you have to include certain plugins and therefore have to do the following:

  1. Go to https://github.com/MrRio/jsPDF and download the latest Version.
  2. Include the following Scripts in your project:
  • jspdf.js
  • jspdf.plugin.from_html.js
  • jspdf.plugin.split_text_to_size.js
  • jspdf.plugin.standard_fonts_metrics.js

If you want to ignore certain elements, you have to mark them with an ID, which you can then ignore in a special element handler of jsPDF. Therefore your HTML should look like this:

<!DOCTYPE html>
<html>
  <body>
    <p id="ignorePDF">don't print this to pdf</p>
    <div>
      <p><font size="3" color="red">print this to pdf</font></p>
    </div>
  </body>
</html>

Then you use the following JavaScript code to open the created PDF in a PopUp:

var doc = new jsPDF();          
var elementHandler = {
  '#ignorePDF': function (element, renderer) {
    return true;
  }
};
var source = window.document.getElementsByTagName("body")[0];
doc.fromHTML(
    source,
    15,
    15,
    {
      'width': 180,'elementHandlers': elementHandler
    });

doc.output("dataurlnewwindow");

For me this created a nice and tidy PDF that only included the line 'print this to pdf'.

Please note that the special element handlers only deal with IDs in the current version, which is also stated in a GitHub Issue. It states:

Because the matching is done against every element in the node tree, my desire was to make it as fast as possible. In that case, it meant "Only element IDs are matched" The element IDs are still done in jQuery style "#id", but it does not mean that all jQuery selectors are supported.

Therefore replacing '#ignorePDF' with class selectors like '.ignorePDF' did not work for me. Instead you will have to add the same handler for each and every element, which you want to ignore like:

var elementHandler = {
  '#ignoreElement': function (element, renderer) {
    return true;
  },
  '#anotherIdToBeIgnored': function (element, renderer) {
    return true;
  }
};

From the examples it is also stated that it is possible to select tags like 'a' or 'li'. That might be a little bit to unrestrictive for the most usecases though:

We support special element handlers. Register them with jQuery-style ID selector for either ID or node name. ("#iAmID", "div", "span" etc.) There is no support for any other type of selectors (class, of compound) at this time.

One very important thing to add is that you lose all your style information (CSS). Luckily jsPDF is able to nicely format h1, h2, h3 etc., which was enough for my purposes. Additionally it will only print text within text nodes, which means that it will not print the values of textareas and the like. Example:

<body>
  <ul>
    <!-- This is printed as the element contains a textnode -->        
    <li>Print me!</li>
  </ul>
  <div>
    <!-- This is not printed because jsPDF doesn't deal with the value attribute -->
    <input type="text" value="Please print me, too!">
  </div>
</body>
Answer from snrlx on Stack Overflow
🌐
npm
npmjs.com › package › html-to-pdf-js
html-to-pdf-js - npm
July 24, 2020 - Update your CI/CD workflows to avoid disruption. Learn more.× ... html2pdf.js converts any webpage or element into a printable PDF entirely client-side using html2canvas and jsPDF.
      » npm install html-to-pdf-js
    
Published   Jul 24, 2020
Version   0.9.3
Author   Erik Koopmans
Top answer
1 of 16
325

jsPDF is able to use plugins. In order to enable it to print HTML, you have to include certain plugins and therefore have to do the following:

  1. Go to https://github.com/MrRio/jsPDF and download the latest Version.
  2. Include the following Scripts in your project:
  • jspdf.js
  • jspdf.plugin.from_html.js
  • jspdf.plugin.split_text_to_size.js
  • jspdf.plugin.standard_fonts_metrics.js

If you want to ignore certain elements, you have to mark them with an ID, which you can then ignore in a special element handler of jsPDF. Therefore your HTML should look like this:

<!DOCTYPE html>
<html>
  <body>
    <p id="ignorePDF">don't print this to pdf</p>
    <div>
      <p><font size="3" color="red">print this to pdf</font></p>
    </div>
  </body>
</html>

Then you use the following JavaScript code to open the created PDF in a PopUp:

var doc = new jsPDF();          
var elementHandler = {
  '#ignorePDF': function (element, renderer) {
    return true;
  }
};
var source = window.document.getElementsByTagName("body")[0];
doc.fromHTML(
    source,
    15,
    15,
    {
      'width': 180,'elementHandlers': elementHandler
    });

doc.output("dataurlnewwindow");

For me this created a nice and tidy PDF that only included the line 'print this to pdf'.

Please note that the special element handlers only deal with IDs in the current version, which is also stated in a GitHub Issue. It states:

Because the matching is done against every element in the node tree, my desire was to make it as fast as possible. In that case, it meant "Only element IDs are matched" The element IDs are still done in jQuery style "#id", but it does not mean that all jQuery selectors are supported.

Therefore replacing '#ignorePDF' with class selectors like '.ignorePDF' did not work for me. Instead you will have to add the same handler for each and every element, which you want to ignore like:

var elementHandler = {
  '#ignoreElement': function (element, renderer) {
    return true;
  },
  '#anotherIdToBeIgnored': function (element, renderer) {
    return true;
  }
};

From the examples it is also stated that it is possible to select tags like 'a' or 'li'. That might be a little bit to unrestrictive for the most usecases though:

We support special element handlers. Register them with jQuery-style ID selector for either ID or node name. ("#iAmID", "div", "span" etc.) There is no support for any other type of selectors (class, of compound) at this time.

One very important thing to add is that you lose all your style information (CSS). Luckily jsPDF is able to nicely format h1, h2, h3 etc., which was enough for my purposes. Additionally it will only print text within text nodes, which means that it will not print the values of textareas and the like. Example:

<body>
  <ul>
    <!-- This is printed as the element contains a textnode -->        
    <li>Print me!</li>
  </ul>
  <div>
    <!-- This is not printed because jsPDF doesn't deal with the value attribute -->
    <input type="text" value="Please print me, too!">
  </div>
</body>
2 of 16
94

This is the simple solution. This works for me. You can use the javascript print concept and simple save this as pdf.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        $("#btnPrint").live("click", function () {
            var divContents = $("#dvContainer").html();
            var printWindow = window.open('', '', 'height=400,width=800');
            printWindow.document.write('<html><head><title>DIV Contents</title>');
            printWindow.document.write('</head><body >');
            printWindow.document.write(divContents);
            printWindow.document.write('</body></html>');
            printWindow.document.close();
            printWindow.print();
        });
    </script>
</head>
<body>
    <form id="form1">
    <div id="dvContainer">
        This content needs to be printed.
    </div>
    <input type="button" value="Print Div Contents" id="btnPrint" />
    </form>
</body>
</html>
Discussions

[AskJS] Is it possible to generate a customized PDF file from a HTML page using JS?
If you can author a PDF form then you could try using https://pdf-lib.js.org to fill it out. More on reddit.com
🌐 r/javascript
9
7
June 19, 2024
Django - Output PDF Based On HTML with JS
You can keep going down the road you’re on now, but I suspect those ways often end up being more painful than doing it the “right” way. Although many developers prefer weasyprint , ReportLab is the preferred library in the Django documentation . ReportLab is the most full-featured library but it also has a learning curve. Here’s a tutorial for adding a chart in ReportLab. More on reddit.com
🌐 r/django
1
1
October 5, 2019
Convert HTML to PDF, any client side js libraries?
jsPDF might be what you are looking for. More on reddit.com
🌐 r/javascript
19
17
February 22, 2016
How do you convert HTML To PDF without a third-party package/library?
You don't? Unless writing it yourself. More on reddit.com
🌐 r/javascript
18
4
May 15, 2018

jsPDF is able to use plugins. In order to enable it to print HTML, you have to include certain plugins and therefore have to do the following:

  1. Go to https://github.com/MrRio/jsPDF and download the latest Version.
  2. Include the following Scripts in your project:
  • jspdf.js
  • jspdf.plugin.from_html.js
  • jspdf.plugin.split_text_to_size.js
  • jspdf.plugin.standard_fonts_metrics.js

If you want to ignore certain elements, you have to mark them with an ID, which you can then ignore in a special element handler of jsPDF. Therefore your HTML should look like this:

<!DOCTYPE html>
<html>
  <body>
    <p id="ignorePDF">don't print this to pdf</p>
    <div>
      <p><font size="3" color="red">print this to pdf</font></p>
    </div>
  </body>
</html>

Then you use the following JavaScript code to open the created PDF in a PopUp:

var doc = new jsPDF();          
var elementHandler = {
  '#ignorePDF': function (element, renderer) {
    return true;
  }
};
var source = window.document.getElementsByTagName("body")[0];
doc.fromHTML(
    source,
    15,
    15,
    {
      'width': 180,'elementHandlers': elementHandler
    });

doc.output("dataurlnewwindow");

For me this created a nice and tidy PDF that only included the line 'print this to pdf'.

Please note that the special element handlers only deal with IDs in the current version, which is also stated in a GitHub Issue. It states:

Because the matching is done against every element in the node tree, my desire was to make it as fast as possible. In that case, it meant "Only element IDs are matched" The element IDs are still done in jQuery style "#id", but it does not mean that all jQuery selectors are supported.

Therefore replacing '#ignorePDF' with class selectors like '.ignorePDF' did not work for me. Instead you will have to add the same handler for each and every element, which you want to ignore like:

var elementHandler = {
  '#ignoreElement': function (element, renderer) {
    return true;
  },
  '#anotherIdToBeIgnored': function (element, renderer) {
    return true;
  }
};

From the examples it is also stated that it is possible to select tags like 'a' or 'li'. That might be a little bit to unrestrictive for the most usecases though:

We support special element handlers. Register them with jQuery-style ID selector for either ID or node name. ("#iAmID", "div", "span" etc.) There is no support for any other type of selectors (class, of compound) at this time.

One very important thing to add is that you lose all your style information (CSS). Luckily jsPDF is able to nicely format h1, h2, h3 etc., which was enough for my purposes. Additionally it will only print text within text nodes, which means that it will not print the values of textareas and the like. Example:

<body>
  <ul>
    <!-- This is printed as the element contains a textnode -->        
    <li>Print me!</li>
  </ul>
  <div>
    <!-- This is not printed because jsPDF doesn't deal with the value attribute -->
    <input type="text" value="Please print me, too!">
  </div>
</body>
Answer from snrlx on Stack Overflow
🌐
PDF Generation API
pdfgeneratorapi.com › home › 3 ways to generate pdf from html with javascript
3 Ways to Generate PDF from HTML with JavaScript - PDF Generator API
May 8, 2025 - HTML2PDF: A library that allows you to convert HTML content into PDF files using JavaScript. Puppeteer: A Node.js library that provides a high-level API to control headless Chrome or Chromium browsers.
🌐
Mozilla
mozilla.github.io › pdf.js
PDF.js - Home
A general-purpose, web standards-based platform for parsing and rendering PDFs.
🌐
DocRaptor
docraptor.com › node-html-to-pdf
Compare Top Node.js HTML to PDF Libraries - Open-Source and Commercial
Puppeteer is a Node.js (no client-side support) library for accessing headless Chromium. It's the most popular open-source HTML-to-PDF converter and has the best support for modern HTML, CSS, and JavaScript. The only downside is Chrome's lack of PDF-specific functionality such as headers and footers, accessible PDFs, page float, to name just a few.
🌐
Nutrient
nutrient.io › blog › sdk › html to pdf in javascript
Convert HTML to PDF with JavaScript: Top libraries compared
August 22, 2025 - Compare four JavaScript HTML-to-PDF solutions: html2pdf.js, pdfmake, Playwright, and Nutrient. Learn how each works, their tradeoffs, and which fits your use case.
Find elsewhere
🌐
html2pdf.js
ekoopmans.github.io › html2pdf.js
html2pdf.js | Client-side HTML-to-PDF rendering using pure JS.
Skip to the content. ... html2pdf.js converts any webpage or element into a printable PDF entirely client-side using html2canvas and jsPDF.
🌐
DEV Community
dev.to › awanshrestha › html-to-pdf-javascript-example-with-code-1eha
HTML to PDF JavaScript – Example with Code - DEV Community
September 17, 2025 - If you're working with .NET/C#, IronPDF is a library that handles HTML to PDF conversion on the server side. IronPDF solves similar issues I’m about to mention in this article: The CSS not loading: IronPDF uses Chrome's rendering engine, so external CSS works as expected. The text not being selectable: IronPDF generates real text in PDFs, not canvas images. Alignment issue with jsPDF: Full CSS3 support means your divs stay where they should.
🌐
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 - Finally, we generate the PDF and close the browser. jsPDF is a JavaScript library that allows you to generate PDF files from HTML programmatically. It works in both Node.js and browser environments.
🌐
Reddit
reddit.com › r/javascript › [askjs] is it possible to generate a customized pdf file from a html page using js?
r/javascript on Reddit: [AskJS] Is it possible to generate a customized PDF file from a HTML page using JS?
June 19, 2024 -

So, I'm trying to generate a PDF file from a Microsoft SharePoint list. The usual method of using CTRL+P doesn't work properly because the information is spread across multiple pages. My idea is to create a "1-page model file" where I have tables for all the user information. This way, I can fill in the blank spaces and then extract it to a PDF. Is that even possible?

🌐
Sejda PDF
sejda.com › html-to-pdf
Convert HTML to PDF Online
3 You're done! Now load a web page in your browser and click the 'Save as PDF' bookmark to convert it to a PDF document. Multiple web pages can be converted at a time. Paste each URL on a separate line. Click Convert HTML to PDF and wait until processing completes.
🌐
PDFCrowd
pdfcrowd.com › html-to-pdf
Convert HTML to PDF Online - PDFCrowd
For quicker conversion, utilize our Save as PDF Browser Addon or bookmarklet. These tools allows you to convert web pages with just a click. To install the bookmarklet, drag the button below to your bookmark bar (video tutorial). ... Turn any webpage or HTML into PDF programmatically.
🌐
React-pdf
react-pdf.org
React-pdf
React renderer for creating PDF files on the browser and server
🌐
ConvertApi
convertapi.com › pdf-to-html › javascript
PDF to HTML Conversion JavaScript SDK – Convert PDF to HTML.
ConvertAPI provides a JavaScript module that allows you to perform a PDF to HTML conversion with just a few lines of code. First, install the convertapi-js@~1.1 package from npm:
🌐
IronPDF
ironpdf.com › how-tos › javascript (custom render delays)
(Step by Step) Using JavaScript in HTML to PDF in C# | IronPDF
This feature allows you to debug and log console messages during the PDF rendering process. Yes, IronPDF can render charts created with D3.js by enabling JavaScript execution in the rendering options and using methods like `RenderHtmlFileAsPdf` to convert HTML files containing chart scripts into PDFs.
Published   July 23, 2025
🌐
Apryse
docs.apryse.com › core › guides › features › conversion › convert-pdf-to-html › js
Server/Desktop PDF to HTML Converter Library in Node.js (JavaScript) | Apryse documentation
Convert PDF to HTML - Sample Code Full sample code which shows how to convert generic PDF documents to HTML format. Sample code provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby, Go and VB.