${data.team_summary.replace(/\n/g, '
')}
`;
}
function generatePdf() {
if (!window.jspdf || !latestGeneratedData) {
alert("Please generate a proposal before downloading.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'letter' });
const pageHeight = doc.internal.pageSize.getHeight();
const pageWidth = doc.internal.pageSize.getWidth();
const margin = 72;
let cursorY = 0;
let pageCount = 1;
const addHeaderFooter = () => {
doc.setFont("Helvetica", "normal");
doc.setFontSize(8);
doc.setTextColor(150);
doc.text(document.getElementById('projectName').value, margin, pageHeight - 40);
doc.text(`Page ${pageCount}`, pageWidth - margin, pageHeight - 40, { align: 'right' });
};
// --- Cover Page ---
doc.setFillColor(248, 250, 252); // Slate 50
doc.rect(0, 0, pageWidth, pageHeight, 'F');
doc.setFont("Georgia", "bold");
doc.setFontSize(28);
doc.setTextColor(30, 41, 59); // Slate 800
doc.text(document.getElementById('projectName').value, pageWidth / 2, pageHeight / 2 - 40, { align: 'center' });
doc.setFontSize(18);
doc.setTextColor(51, 65, 85); // Slate 700
doc.text("Investment Proposal", pageWidth / 2, pageHeight / 2 - 15, { align: 'center' });
doc.setFont("Helvetica", "normal");
doc.setFontSize(10);
doc.text(new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }), pageWidth / 2, pageHeight / 2 + 10, { align: 'center' });
// --- Proposal Content ---
doc.addPage();
addHeaderFooter();
cursorY = margin;
const drawSection = (title, content) => {
if (!content) return;
doc.setFont("Georgia", "bold");
doc.setFontSize(16);
doc.setTextColor(30, 41, 59);
const titleLines = doc.splitTextToSize(title, pageWidth - margin*2);
if (cursorY + (titleLines.length * 18) + 20 > pageHeight - 60) { doc.addPage(); pageCount++; addHeaderFooter(); cursorY = margin; }
doc.text(title, margin, cursorY);
cursorY += titleLines.length * 18 + 10;
doc.setDrawColor(226, 232, 240);
doc.line(margin, cursorY - 5, margin + 150, cursorY - 5);
doc.setFont("Helvetica", "normal");
doc.setFontSize(11);
doc.setTextColor(51, 65, 85);
const textLines = doc.splitTextToSize(content, pageWidth - margin * 2);
if (cursorY + (textLines.length * 12 * 1.5) > pageHeight - 60) { doc.addPage(); pageCount++; addHeaderFooter(); cursorY = margin; }
doc.text(textLines, margin, cursorY, { lineHeightFactor: 1.5 });
cursorY += textLines.length * 12 * 1.5 + 25;
};
drawSection("Executive Summary", latestGeneratedData.executive_summary);
drawSection("Market Analysis", latestGeneratedData.market_analysis);
drawSection("Financial Plan", latestGeneratedData.financial_plan);
drawSection("Team", latestGeneratedData.team_summary);
const safeFileName = (document.getElementById('projectName').value || 'investment_proposal').replace(/[^a-z0-9]/gi, '_').toLowerCase();
doc.save(`${safeFileName}.pdf`);
}
// Initial setup
showTab(1);
createDynamicField(teamContainer, 'Name (e.g., Jane Doe)', 'Role (e.g., CEO)', ()=>{});
createDynamicField(teamContainer, 'Name (e.g., John Smith)', 'Role (e.g., CTO)', ()=>{});
createDynamicField(fundsContainer, 'Item (e.g., R&D)', 'Amount ($)', ()=>{});
});