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
🌐
jsPDF
artskydj.github.io › jsPDF › docs › jsPDF.html
jsPDF - Documentation
Sets the line join styles. See {jsPDF.CapJoinStyles} for variants. ... Sets the miterLimit property, which effects the maximum miter length. ... Sets line width for upcoming lines. ... Adds (and transfers the focus to) new page to the PDF document.
🌐
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
🌐
jsPDF
artskydj.github.io › jsPDF › docs › index.html
Home - Documentation
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 ...
🌐
Parallax
parall.ax › products › jspdf
jsPDF
Our documentation is generated from the source code, and we ensure it's up-to-date and comprehensive.
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>
🌐
Escalent
webmedia.escalent.co › Archive › Projects › jsPDF › jsPDF-master › docs › jspdf.js.html
jspdf.js - Documentation
* @param {string} pmode 'UseOutlines' - it shows the * outline of the document on the left. 'UseThumbs' - shows thumbnails along * the left. 'FullScreen' - prompts the user to enter fullscreen mode. * * @returns {jsPDF} */ API.__private__.setDisplayMode = API.setDisplayMode = function (zoom, layout, pmode) { setZoomMode(zoom); setLayoutMode(layout); setPageMode(pmode); return this; }; var documentProperties = { 'title': '', 'subject': '', 'author': '', 'keywords': '', 'creator': '' }; API.__private__.getDocumentProperty = function (key) { if (Object.keys(documentProperties).indexOf(key) === -1) { throw new Error('Invalid argument passed to jsPDF.getDocumentProperty'); } return documentProperties[key]; }; API.__private__.getDocumentProperties = function () { return documentProperties; }; /** * Adds a properties to the PDF document.
🌐
Euritmia-ocupacional
euritmia-ocupacional.org › Plugins › html2pdf-js › jsPDF-master › docs › jspdf.js.html
jspdf.js - Documentation
* @function * @instance * @returns {jsPDF} * @memberof jsPDF# * @name setDocumentProperties */ API.__private__.setDocumentProperties = API.setProperties = API.setDocumentProperties = function( properties ) { // copying only those properties we can render. for (var property in documentProperties) { if (documentProperties.hasOwnProperty(property) && properties[property]) { documentProperties[property] = properties[property]; } } return this; }; API.__private__.setDocumentProperty = function(key, value) { if (Object.keys(documentProperties).indexOf(key) === -1) { throw new Error("Invalid arguments passed to jsPDF.setDocumentProperty"); } return (documentProperties[key] = value); }; var fonts = {}; // collection of font objects, where key is fontKey - a dynamically created label for a given font.
🌐
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 - The constructor function of the jsPDF class takes an object as a parameter with the following three properties: Orientation – Defines the orientation of the PDF document.
Find elsewhere
🌐
Gaam-akhar
gaam-akhar.ir › assets › jspdf › docs › jspdf.js.html
jspdf.js - Documentation
See {@link setGState}. * @param {String} key * @param {GState} gState * @function * @returns {jsPDF} * * @methodOf jsPDF# * @name addGState */ API.addGState = function(key, gState) { addGState(key, gState); return this; }; /** * Adds (and transfers the focus to) new page to the PDF document.
🌐
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.
🌐
Read the Docs
app.readthedocs.org › projects › jspdf
jsPDF - Read the Docs Community
jsPDF · EN · Maintainers · Repository https://github.com/VikingRock/jsPDF · Versions 2 Builds 148 · View docs · Debug information · Spam score 249 · Spam matching rules · InvalidGitRepository ·
🌐
MicroPyramid
micropyramid.com › blog › export-html-web-page-to-pdf-using-jspdf
Export HTML Web Page to PDF Using JsPDF | MicroPyramid
var doc = new jsPDF(); doc.ellipse(40, 20, 10, 5); doc.setFillColor(0,0,255); doc.ellipse(80, 20, 10, 5, 'F'); doc.setLineWidth(1); doc.setDrawColor(0); doc.setFillColor(255,0,0); doc.circle(120, 20, 5, 'FD'); Now, we are going to know about an interesting functionality over here - addHTML(): The below example will show you a preview of the html document that you've added this jsPDF script to generate pdf.
🌐
Tizen
developer.tizen.org › community › tip-tech › creating-pdf-documents-jspdf
Creating PDF documents with jsPDF
unit – We can tell jsPDF in which units we want to work. Use one of the following: “pt” (points), “mm” (default), “cm”, “in”. format – It’s default page format. It can be “a3”, “a4” (default), “a5”, “letter”, “legal”. We can add new page using the following code. ... As parameters we pass the page, width and height in the units defined in the document constructor.
🌐
GitHub
github.com › parallax › jsPDF
GitHub - parallax/jsPDF: Client-side JavaScript PDF generation for everyone.
jspdf.umd.*.js: UMD module format.
Starred by 30.9K users
Forked by 4.8K users
Languages   JavaScript 96.4% | TypeScript 2.4% | HTML 1.2%
🌐
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
🌐
Mrrio
mrrio.github.io › jsPDF › examples › basic.html
jsPDF
var doc = new jsPDF(); doc.text(20, 20, 'This PDF has a title, subject, author, keywords and a creator.'); // Optional - set properties on the document doc.setProperties({ title: 'Title', subject: 'This is the subject', author: 'James Hall', keywords: 'generated, javascript, web 2.0, ajax', creator: 'MEEE' }); // Output as Data URI doc.save('Test.pdf'); Run Code
🌐
Pub.dev
pub.dev › documentation › jspdf › latest
jspdf - Dart API docs
<!doctype html> <html> <head> <title>jsPDF/ and Dart interop example</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script> <script src="https://raw.githack.com/yWorks/svg2pdf.js/master/dist/svg2pdf.umd.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.25/jspdf.plugin.autotable.min.js"></script> <script defer type="application/javascript" src="example.dart.js"></script> <style type="text/css"> html, body { margin: 0; background-color: rgb(211, 211, 211); height: 100%; font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; } .main { display: flex; justify-content: center; align-items: center; height: 100%; } iframe{ border: none; width: 70%; height: 95%; } </style> </head> <body> <div class="main"> <iframe id="pdf-iframe"></iframe> </div> </body> </html>