Created
July 11, 2016 22:23
-
-
Save arianimartins/4df398a9e6aeaaf47e1d2b6274cecafd to your computer and use it in GitHub Desktop.
HTML to PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<div id="content"> | |
<h1>Title</h1> | |
<article> Content </article> | |
</div> | |
<div id="editor"></div> | |
<button id="cmd">.PDF</button> | |
</body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.js"></script> | |
<script> | |
$(document).ready(function(){ | |
var doc = new jsPDF(); | |
var specialElementHandlers = { | |
'#editor': function(element, renderer){ | |
return true; | |
} | |
}; | |
$('#cmd').click(function () { | |
doc.fromHTML($('#content').get(0), 15, 15, { | |
'width': 170, | |
'elementHandlers': specialElementHandlers | |
}); | |
doc.save('file.pdf'); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment