${thesis.replace(/\n/g, '
')}
Key Risks
${risks.replace(/\n/g, '
')}
`;
initialMessage.classList.add('hidden');
resultsContainer.classList.remove('hidden');
pdfButtonContainer.classList.remove('hidden');
};
downloadPdfBtn.addEventListener('click', () => {
if (!lastSummaryData) return;
const { jsPDF } = window.jspdf;
const { name, ticker, overview, revenue, netIncome, eps, pe, thesis, risks } = lastSummaryData;
const doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
const pageW = doc.internal.pageSize.getWidth();
const margin = 50;
let y = 0;
// PDF Header
doc.setFillColor('#0f172a'); // slate-900
doc.rect(0, 0, pageW, 70, 'F');
doc.setFont('helvetica', 'bold');
doc.setFontSize(24);
doc.setTextColor('#ffffff');
doc.text(name, margin, 45);
doc.setFontSize(16);
doc.setTextColor('#94a3b8'); // slate-400
doc.text(`Ticker: ${ticker}`, pageW - margin, 45, { align: 'right' });
y = 100;
// Helper function for sections
const addSection = (title, textContent) => {
if (y > doc.internal.pageSize.getHeight() - 100) { doc.addPage(); y = margin; }
doc.setFont('helvetica', 'bold');
doc.setFontSize(14);
doc.setTextColor('#0369a1'); // sky-700
doc.text(title, margin, y);
y += 20;
doc.setFont('helvetica', 'normal');
doc.setFontSize(11);
doc.setTextColor('#334155'); // slate-700
const lines = doc.splitTextToSize(textContent, pageW - margin * 2);
doc.text(lines, margin, y);
y += lines.length * 14 + 15;
};
addSection('Investment Thesis', thesis);
addSection('Company Overview', overview);
// Financials Table
doc.setFont('helvetica', 'bold');
doc.setFontSize(14);
doc.setTextColor('#0369a1');
doc.text('Financial Snapshot (TTM)', margin, y);
y += 20;
doc.autoTable({
startY: y,
head: [['Metric', 'Value']],
body: [
['Revenue', `$${revenue.toFixed(1)}B`],
['Net Income', `$${netIncome.toFixed(1)}B`],
['EPS', `$${eps.toFixed(2)}`],
['P/E Ratio', `${pe.toFixed(1)}x`]
],
theme: 'striped',
headStyles: { fillColor: '#0ea5e9' }, // sky-500
styles: { font: 'helvetica', fontSize: 11, cellPadding: 8 },
});
y = doc.autoTable.previous.finalY + 30;
addSection('Key Risks', risks);
// Footer
const date = `Report Generated: ${new Date().toLocaleDateString('en-US')}`;
doc.setFontSize(9);
doc.setTextColor('#64748b');
doc.text(date, pageW / 2, doc.internal.pageSize.getHeight() - 20, { align: 'center' });
doc.save(`Equity_Summary_${ticker}.pdf`);
});
showTab(0);
});