Forum Discussion
Modifying report.html to include slide name
Thank you for the responses! Jose - I appreciate the thread reference; unfortunately, the links in the thread are no longer active.
Nedim - you confirmed what I was worried about! I really wanted to make the h3 element dynamic based on which results slide the user is on. Do you know if I could use javascript to download the report.html output as a pdf instead of opening a new tab? I'm thinking that I could then specify a file name that corresponds to the slide title within the script -- which is a workaround to being able to include it right in the document.
- Nedim3 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.