Last active
November 1, 2018 06:32
-
-
Save hd9/b3f30966c0edaf472023cd71c48f7565 to your computer and use it in GitHub Desktop.
A simple js-pdf exporter
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
<html> | |
<head> | |
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js"></script> | |
<script> | |
$(document).ready(function(){ | |
$('#cmd').click(function () { | |
doc.fromHTML($('#content').html(), 15, 15, { | |
'width': 170, | |
'elementHandlers': specialElementHandlers | |
}); | |
doc.save('sample-file.pdf'); | |
}); | |
}); | |
var doc = new jsPDF(); | |
var specialElementHandlers = { | |
'#editor': function (element, renderer) { | |
return true; | |
} | |
}; | |
</script> | |
</head> | |
<body> | |
<div id="content"> | |
<h1>Lorem Ipsum</h1> | |
<p>Minus soluta non animi laboriosam voluptas pariatur. Sed eos temporibus culpa dolores iure nulla. Et ut nihil consectetur libero molestiae aut. Reiciendis et impedit officiis veniam quisquam rerum.</p> | |
<p>Aperiam ipsam qui ipsam ut quaerat ut reiciendis quis. Ea rerum ducimus rerum nam fugit modi. Qui molestiae nesciunt distinctio aliquid nam. Est culpa tenetur tenetur eos ut nisi quia qui. Recusandae debitis sed voluptatem. Et quia quisquam adipisci numquam dolores est sit ipsum.</p> | |
<p>Quaerat sint harum provident nihil totam sunt. Quia dolorem aut iste doloremque et suscipit animi. Distinctio unde doloremque aut et sequi.</p> | |
</div> | |
<p>More info can be found at <a href="https://blog.hildenco.com/2018/02/a-simple-js-to-pdf-exporter.html">https://blog.hildenco.com/2018/02/a-simple-js-to-pdf-exporter.html</a></p> | |
<div id="editor"></div> | |
<button id="cmd">Generate PDF</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to generate pdf files from JavaScript pages and Html?
For more information, visit this post:
https://blog.hildenco.com/2018/02/a-simple-js-to-pdf-exporter.html