Principal Returned
${formatCurrency(finalPrincipal)}
Net Return
${formatCurrency(netReturn)}
Total ROI
${roi.toFixed(2)}%
`;
document.getElementById('eeb-results-output').innerHTML = resultsHTML;
document.getElementById('eeb-pdf-download-btn').style.display = 'block';
eeb_showTab('results');
};
window.eeb_downloadPDF = () => {
if (typeof html2canvas === 'undefined' || typeof window.jspdf === 'undefined') {
alert('PDF library is still loading. Please try again in a moment.');
return;
}
const { jsPDF } = window.jspdf;
const content = document.querySelector('#eeb-tab-results'); // Capture whole tab content
const downloadButton = document.getElementById('eeb-pdf-download-btn');
if (downloadButton) downloadButton.style.display = 'none';
html2canvas(content, { scale: 2 }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const imgWidth = pdfWidth - 20;
const imgHeight = (canvas.height * imgWidth) / canvas.width;
pdf.setFont("helvetica", "bold");
pdf.setFontSize(16);
pdf.text("Catastrophe Bond Analysis Report", pdfWidth / 2, 18, { align: 'center' });
pdf.addImage(imgData, 'PNG', 10, 30, imgWidth, imgHeight);
pdf.save('Catastrophe_Bond_Analysis.pdf');
if (downloadButton) downloadButton.style.display = 'block';
});
};
});