you can use pdf from html as follows,

Step 1: Add the following script to the header

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>

or download locally

Step 2: Add HTML script to execute jsPDF code

Customize this to pass the identifier or just change #content to be the identifier you need.

 <script>
    function demoFromHTML() {
        var pdf = new jsPDF('p', 'pt', 'letter');
        // source can be HTML-formatted string, or a reference
        // to an actual DOM element from which the text will be scraped.
        source = $('#content')[0];

        // 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.
        specialElementHandlers = {
            // element with id of "bypass" - jQuery style selector
            '#bypassme': function (element, renderer) {
                // true = "handled elsewhere, bypass text extraction"
                return true
            }
        };
        margins = {
            top: 80,
            bottom: 60,
            left: 40,
            width: 522
        };
        // all coords and widths are in jsPDF instance's declared units
        // 'inches' in this case
        pdf.fromHTML(
            source, // HTML string or DOM elem ref.
            margins.left, // x coord
            margins.top, { // y coord
                'width': margins.width, // max width of content on PDF
                'elementHandlers': specialElementHandlers
            },

            function (dispose) {
                // dispose: object with X, Y of the last line add to the PDF 
                //          this allow the insertion of new lines after html
                pdf.save('Test.pdf');
            }, margins
        );
    }
</script>

Step 3: Add your body content

<a href="javascript:demoFromHTML()" class="button">Run Code</a>
<div id="content">
    <h1>  
        We support special element handlers. Register them with jQuery-style.
    </h1>
</div>

Refer to the original tutorial

See a working fiddle

Answer from Well Wisher on Stack Overflow
🌐
Mrrio
mrrio.github.io › jsPDF › examples › basic.html
jsPDF
var doc = new jsPDF(); doc.text(20, 20, 'Hello world!'); doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.'); doc.addPage(); doc.text(20, 20, 'Do you like that?'); doc.save('Test.pdf'); Run Code
🌐
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 - Here’s an in-depth guide where we break down JsPDF, an open source solution that can help you quickly generate high quality PDFs from HTML.
🌐
jsPDF
artskydj.github.io › jsPDF › docs › jsPDF.html
jsPDF - Documentation
Sets text font face, variant for upcoming text elements. See output of jsPDF.getFontList() for possible font names, styles.
🌐
GitHub
github.com › parallax › jsPDF
GitHub - parallax/jsPDF: Client-side JavaScript PDF generation for everyone.
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%
Top answer
1 of 7
154

you can use pdf from html as follows,

Step 1: Add the following script to the header

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>

or download locally

Step 2: Add HTML script to execute jsPDF code

Customize this to pass the identifier or just change #content to be the identifier you need.

 <script>
    function demoFromHTML() {
        var pdf = new jsPDF('p', 'pt', 'letter');
        // source can be HTML-formatted string, or a reference
        // to an actual DOM element from which the text will be scraped.
        source = $('#content')[0];

        // 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.
        specialElementHandlers = {
            // element with id of "bypass" - jQuery style selector
            '#bypassme': function (element, renderer) {
                // true = "handled elsewhere, bypass text extraction"
                return true
            }
        };
        margins = {
            top: 80,
            bottom: 60,
            left: 40,
            width: 522
        };
        // all coords and widths are in jsPDF instance's declared units
        // 'inches' in this case
        pdf.fromHTML(
            source, // HTML string or DOM elem ref.
            margins.left, // x coord
            margins.top, { // y coord
                'width': margins.width, // max width of content on PDF
                'elementHandlers': specialElementHandlers
            },

            function (dispose) {
                // dispose: object with X, Y of the last line add to the PDF 
                //          this allow the insertion of new lines after html
                pdf.save('Test.pdf');
            }, margins
        );
    }
</script>

Step 3: Add your body content

<a href="javascript:demoFromHTML()" class="button">Run Code</a>
<div id="content">
    <h1>  
        We support special element handlers. Register them with jQuery-style.
    </h1>
</div>

Refer to the original tutorial

See a working fiddle

2 of 7
19

You only need this link jspdf.min.js

It has everything in it.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
🌐
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
🌐
OpenReplay
blog.openreplay.com › generating-a-pdf-from-a-div-using-the-jspdf-library
Generating a PDF from a div using the jsPDF Library
In this article, we have learned to use jsPDF and other libraries like html2canvas and html2pdf to generate PDFs from a web page div.
Find elsewhere
🌐
Source Code Tester
sourcecodester.com › tutorial › javascript › 16017 › generating-pdf-file-using-javascript-and-jspdf-library-tutorial
Generating PDF File using JavaScript and JSPDF Library Tutorial | SourceCodester
This tutorial will teach you how to generate or create a PDF File on the client side using JavaScript and JSPDF Library. Here, sample snippets and working source code zip file are provided and free to download.
🌐
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.
🌐
Phppot
phppot.com › javascript › html-to-pdf-in-javascript-using-jspdf
HTML to PDF in Javascript using jsPDF with Example Download - Phppot
She specializes in building modern, lightweight websites using PHP, JavaScript, React, and related technologies. Phppot helps you in mastering web development through over a decade of publishing quality tutorials. How to use js PDF Library to generate PDF from HTML · jsPDF HTML Example with html2canvas for Multiple Pages PDF
🌐
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
🌐
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.
🌐
YouTube
youtube.com › playlist
jsPDF Tutorial for Beginners | Make PDF Documents in jsPDF - YouTube
In this Playlist we will be learning about jsPDF Library a library which will be useful to create PDF Documents from HTML Documents.
🌐
C# Corner
c-sharpcorner.com › UploadFile › b629e0 › creating-pdf-from-html-through-jspdf
Creating PDF From HTML Using JSPDF
June 7, 2024 - Learn how to create PDFs from HTML using the jsPDF library in this comprehensive guide. Discover the step-by-step process to convert your HTML content into a PDF document effortlessly with JavaScript.
🌐
Tizen
developer.tizen.org › community › tip-tech › creating-pdf-documents-jspdf
Creating PDF documents with jsPDF
In the previous article Displaying PDF files with PDF.js library we have showed how to display PDF files on the HTML canvas. In this article, we will show how to create PDF files from scratch. We will use jsPDF library for this purpose. You can download the newest library version just from ...
🌐
Appsmith
community.appsmith.com › tutorial › data-driven-pdf-generator-jspdf-and-autotable
Data-Driven PDF Generator with JSPDF and Autotable | Appsmith Community Portal
October 12, 2024 - In this guide, we'll be using the JSPDF library and the JSPDF-AutoTable plug-in to generate PDFs from customer order data. This method builds a PDF programmatically, one line at a time, as opposed to other methods that use a template or HTML.
🌐
PDFBolt
pdfbolt.com › blog › generate-html-to-pdf-with-jspdf
Generate PDFs with jsPDF: A Complete Guide to Client-Side PDF Creation | PDFBolt
March 13, 2025 - Master client-side PDF generation with jsPDF and html2canvas. Learn to create interactive forms, convert HTML to PDF, and build downloadable documents–all without server processing.
🌐
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.
🌐
CodeSandbox
codesandbox.io › examples › package › jspdf
jspdf examples - CodeSandbox
Use this online jspdf playground to view and fork jspdf example apps and templates on CodeSandbox.