Created
February 4, 2025 17:01
-
-
Save vikasnkumar/7e161ac5b218b5a03b0d9316bd28cb1b to your computer and use it in GitHub Desktop.
HTML TO PDF via JS
This file contains hidden or 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
$('#pdf_export_button').click(function(e) { | |
e.preventDefault(); | |
var rname = "screen.pdf"; | |
try { | |
//NOTE: layout_main is the name of the DIV that you want to export to PDF. | |
var element = document.getElementById('layout_main'); | |
var myopt = { filename: rname, image: { type: 'jpeg', quality: 0.9 }, jsPDF: { orientation: 'landscape' } }; | |
html2pdf().set(myopt).from(element).save().then(function() { | |
console.log("PDF has been generated"); | |
}); | |
console.log("Export as PDF to " + rname); | |
} catch (err) { | |
console.error("Error in pdf generation: " + err); | |
} | |
}); |
This file contains hidden or 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://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js" | |
integrity="sha512-GsLlZN/3F2ErC5ifS5QtgpiJtWd43JWSuIgh7mbzZ8zBps+dvLusV+eNQATqgA/HdeKFVgA5v3S/cIrLF7QnIg==" | |
crossorigin="anonymous" | |
referrerpolicy="no-referrer"></script> | |
</head> | |
<body> | |
<a href="https://ekoopmans.github.io/html2pdf.js/">Github Repo</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment