Skip to content

Instantly share code, notes, and snippets.

@arianimartins
Created July 11, 2016 22:23
Show Gist options
  • Save arianimartins/4df398a9e6aeaaf47e1d2b6274cecafd to your computer and use it in GitHub Desktop.
Save arianimartins/4df398a9e6aeaaf47e1d2b6274cecafd to your computer and use it in GitHub Desktop.
HTML to PDF
<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