Cycling Speed Calculator

Distance: ${distance} ${currentUnit}

Time Taken: ${timeString}

`; const pdfResults = resultsArea.cloneNode(true); pdfResults.style.display = 'block'; pdfExportContainer.innerHTML = pdfTitle + pdfSummary; pdfExportContainer.appendChild(pdfResults); document.body.appendChild(pdfExportContainer); try { const canvas = await html2canvas(pdfExportContainer, { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgHeight = canvas.height * pdfWidth / canvas.width; pdf.addImage(imgData, 'PNG', 10, 10, pdfWidth - 20, imgHeight - 20); pdf.save('Cycling-Speed-Results.pdf'); } catch (error) { console.error("PDF Generation Failed:", error); alert("An error occurred while generating the PDF."); } finally { document.body.removeChild(pdfExportContainer); } }; // --- Event Listeners --- calculateBtn.addEventListener('click', calculateSpeed); pdfBtnContainer.querySelector('button')?.addEventListener('click', downloadPDF); });
Scroll to Top