Generate PDF from HTML using JQuery and jsPDF

In some applications, there can be a scenario to generate pdf from current page. It is possible using JQuery and jsPDF.

Lets check sample code for generating PDF

Add libraries- JQuery and jsPDF

<script src=""></script>
<script src=""></script>

Sample HTML to download

<div id="content">
    <h3>Sample h3 tag</h3>
    <p>Sample pararaph</p>
<button id="cmd">Generate PDF</button>

Script to generate and download PDF from HTML

var doc = new jsPDF();

$('#cmd').click(function () {   
    doc.fromHTML($('#content').html(), 15, 15, {
        'width': 170,
            'elementHandlers': specialElementHandlers

Find working sample code from the codepen URL -