`;
this.dom.exampleInvestments.innerHTML += investmentItem;
});
},
generatePdf() {
if (!this.portfolioData) return;
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ unit: 'pt', format: 'a4' });
const { allocation, amount, etfs, userInputs } = this.portfolioData;
pdf.setFontSize(20);
pdf.text("Your Personalized Investment Portfolio", 40, 60);
pdf.setFontSize(10);
pdf.text(`Report Generated on: ${new Date().toLocaleDateString()}`, 40, 75);
const chartImage = this.chartInstance.toBase64Image();
pdf.addImage(chartImage, 'PNG', 40, 100, 200, 200);
const tableBody = Object.keys(userInputs).map(key => [
key.charAt(0).toUpperCase() + key.slice(1), userInputs[key]
]);
tableBody.push(['Initial Investment', amount.toLocaleString('en-US', { style: 'currency', currency: 'USD' })]);
pdf.autoTable({
startY: 100,
startX: 260,
head: [['Your Profile', '']],
body: tableBody,
headStyles: { fillColor: [37, 99, 235] }
});
const allocationData = Object.keys(allocation).map(key => [
key, `${allocation[key]}%`, etfs[key].ticker, etfs[key].name
]);
pdf.autoTable({
startY: 320,
head: [['Asset Class', 'Allocation', 'Example ETF', 'Description']],
body: allocationData,
headStyles: { fillColor: [37, 99, 235] }
});
pdf.save('Investment-Portfolio.pdf');
}
};
app.init();
});