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, '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', ...
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>
🌐
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 - See the JSPDF docs for more details and other methods. Run the function and you should get back a DataUrl. This is a base64 representation of the file, and can be used in place of a URL to display the PDF in a DocumentViewer widget. For more info on DataUrls and Base64, check out this post. ... The PDF should now be displaying in the DocumentViewer. Next, we need some sample data to display in a table on the PDF. For this example, we'll be using hard-coded sample data, but you can swap this out for your own datasource as needed.
🌐
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.
🌐
GitHub
github.com › parallax › jsPDF
GitHub - parallax/jsPDF: Client-side JavaScript PDF generation for everyone.
The 14 standard fonts in PDF are limited to the ASCII-codepage. If you want to use UTF-8 you have 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.
Starred by 30.9K users
Forked by 4.8K users
Languages   JavaScript 96.4% | TypeScript 2.4% | HTML 1.2%
🌐
CodePen
codepen.io › ianaya89 › pen › JoRNyK
jsPDF Demo
var content = document.getElementById('txtContent'), button = document.getElementById('btnDownload'); function generatePDF(){ var doc = new jsPDF(); doc.setFontSize(14); doc.text(20, 20, content.value); //doc.text(35, 25, "Paranyan loves jsPDF"); ...
Find elsewhere
🌐
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.
🌐
Phppot
phppot.com › javascript › jspdf-autotable
jsPDF AutoTable example – Table to PDF - Phppot
December 3, 2022 - The below code shows a quick example to learn how to use the jsPDF autoTable library to convert tabular data into a PDF.
🌐
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 - Above shown is the output of the template. Now comes the star of the show, jsPDF part First, Set up jsPDF To use jsPDF, you need to include the library in your HTML file. You can either download the library and include it locally, or you can include it directly from a CDN.
🌐
JSFiddle
jsfiddle.net › H3h99
jsPDF Example - 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 › jsPDF.html
jsPDF - Documentation
Saves as PDF document. An alias of jsPDF.output('save', 'filename.pdf').
🌐
CloudDefense.ai
clouddefense.ai › code › javascript › example › jspdf
Top 10 Examples of jspdf code in Javascript
generatePDF = () => { const now ...getFormatedDateAndTime(this.props.activeReport.endTime)}`; console.log(startTime, 123); // create a new pdf const doc = new jsPDF(); // doc title doc.setFontSize(28) doc.text(20, 25, `Checkin Report`); // sub title (Room Name) doc.setFontSize(14); ...
🌐
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
🌐
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 - Anyway, jsPDF is very easy for basic PDF files generation. Take a look to a simple “Hello World” example:
🌐
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 - For this tutorial, we will write a simple HTML invoice code that we will use to demonstrate how jsPDF works.
🌐
npm
npmjs.com › package › jspdf
jspdf - npm
4 weeks ago - The 14 standard fonts in PDF are limited to the ASCII-codepage. If you want to use UTF-8 you have 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.
      » npm install jspdf
    
Published   Nov 19, 2025
Version   3.0.4