`;
document.getElementById('pdf-chart-img').src = roiChart.toBase64Image();
const tableHTML = `
`;
document.getElementById('pdf-table-container').innerHTML = tableHTML;
// 2. Render and save
const pdfContainer = document.getElementById('pdf-container');
pdfContainer.classList.remove('invisible', '-left-[9999px]');
try {
const canvas = await html2canvas(document.getElementById('pdf-report'), { scale: 2 });
const imgData = canvas.toDataURL('image/jpeg', 0.9);
const pdf = new jsPDF({ orientation: 'p', unit: 'px', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'JPEG', 0, 0, pdfWidth, pdfHeight);
pdf.save('Affiliate_ROI_Analysis_Report.pdf');
} catch (error) { console.error("PDF generation failed:", error); }
finally { pdfContainer.classList.add('invisible', '-left-[9999px]'); }
}
initialize();
});
| Campaign | ROI | Net Profit | CPA | Revenue | Costs |
|---|---|---|---|---|---|
| ${c.name} | ${c.roi.toFixed(1)}% | $${c.netProfit.toFixed(2)} | $${c.cpa.toFixed(2)} | $${c.revenue.toFixed(2)} | $${c.totalCosts.toFixed(2)} |
