Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

javascript generate pdf from div content jquery

<!--html-->
<div id="content">
     <h3>Hello, this is a H3 tag</h3>

    <p>A paragraph</p>
</div>
<div id="editor"></div>
<button id="cmd">generate PDF</button>

<!--import the script-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.2.0/jspdf.umd.min.js"></script>

<!--the script-->
<script>
var doc = new jsPDF();
var specialElementHandlers = {
    '#editor': function (element, renderer) {
        return true;
    }
};

$('#cmd').click(function () {
    doc.fromHTML($('#content').html(), 15, 15, {
        'width': 170,
            'elementHandlers': specialElementHandlers
    });
    doc.save('sample-file.pdf');
});
</script>
 
PREVIOUS NEXT
Tagged: #javascript #generate #pdf #div #content #jquery
ADD COMMENT
Topic
Name
1+9 =