Skip to content

Instantly share code, notes, and snippets.

@hd9 hd9/js-pdf-exporter.html
Last active Nov 1, 2018

Embed
What would you like to do?
A simple js-pdf exporter
<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>
@hd9

This comment has been minimized.

Copy link
Owner Author

commented Nov 1, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.