Forum Discussion
skuda
8 months agoCommunity Member
Modifying report.html to include slide name
Hello! I am hoping for some assistance from the community. I have a course -- really a self-assessment -- with multiple categories. Each category includes a quiz and a results slide. Each result s...
Nedim
8 months agoCommunity Member
You would have to modify report.html after being published to Web. Insert this script right before </body> at the bottom of report.html document.
<script>
document.addEventListener("DOMContentLoaded", function () {
function loadScript(src, callback) {
var script = document.createElement("script");
script.src = src;
script.onload = callback;
document.head.appendChild(script);
}
loadScript("https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js", function () {
loadScript("https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js", function () {
generatePDF();
});
});
function generatePDF() {
const { jsPDF } = window.jspdf;
var doc = new jsPDF({
orientation: "p",
unit: "mm",
format: "a4"
});
html2canvas(document.body, { scale: 1 }).then(canvas => {
var imgData = canvas.toDataURL("image/png");
var imgWidth = 210;
var pageHeight = 297;
var imgHeight = (canvas.height * imgWidth) / canvas.width;
doc.addImage(imgData, "PNG", 0, 0, imgWidth, imgHeight);
doc.save("Results.pdf");
// Close the tab after saving the PDF, with a slight delay to ensure the save dialog appears first
setTimeout(function () {
window.close();
}, 100);
});
}
});
</script>
Result:
You can play with different formats according to jsPDF documentation and update the code accordingly.
Related Content
- 6 months ago
- 6 months ago