You can do it using jsPDF
OR
HTML:
<div id="content">
<h3>Hello, this is a H3 tag</h3>
<p>a pararaph</p>
</div>
<div id="editor"></div>
<button id="cmd">generate PDF</button>
JavaScript:
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');
});
OUTPUT EXAMPLE
Hemant Vishwakarma - Programming Blog, Tutorials, jQuery, Ajax, PHP, MySQL Code
Software & Website Developer Expert in Core PHP, Yii, Wordpress, Codeignter,
Laravel, Bootstrap, javaScript, CSS,Ajax etc. Web design / Development
Download a div in a HTML page as pdf using javascript
No comments:
Post a Comment