Download HTML’s DIV section’s matter in PDF format. Just use jQuery in your website and make download button for download DIV’s matter in PDF.
How To Do
- First of all Add some code in your DIV section like –
<div id="content"> <h3>Hello, this is a H3 tag</h3> <p>A paragraph</p> </div> <button id="cmd">Download PDF</button>
- Then add Given code in your website’s theme in any where.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.2.0/jspdf.umd.min.js"></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>
Note –
If you are use this code in WordPress. So change something for SAVE title name of post.
doc.save(‘<? php the_title() ?>’);
Hope this code work perfectly in your website. have another query so contact me via contact us section.