Analysis Summary
${risk.advice}
Key Risk Factors Identified
${reasonsHTML}
`;
// Prepare PDF content
preparePdfContent(data, risk);
}
function preparePdfContent(data, risk) {
const pdfContent = document.getElementById('pdf-content');
if(!pdfContent) return;
const tableData = {
"Project Name": data.projectName,
"Project Stage": document.getElementById('projectStage').options[document.getElementById('projectStage').selectedIndex].text,
"Funding Use": document.getElementById('fundingUse').options[document.getElementById('fundingUse').selectedIndex].text,
"Creator Experience": document.getElementById('creatorExperience').options[document.getElementById('creatorExperience').selectedIndex].text,
"Team Expertise": document.getElementById('teamExpertise').options[document.getElementById('teamExpertise').selectedIndex].text,
"Communication": document.getElementById('creatorCommunication').options[document.getElementById('creatorCommunication').selectedIndex].text,
"Reward Complexity": document.getElementById('rewardComplexity').options[document.getElementById('rewardComplexity').selectedIndex].text,
"Funding Goal": `$${data.fundingGoal.toLocaleString()}`,
"Amount Raised": `$${data.amountRaised.toLocaleString()}`,
"Days Left": data.daysLeft,
"Backers": data.backers,
};
const tableRowsHTML = Object.entries(tableData).map(([key, value]) => `
| ${key} | ${value} |
|---|
`).join('');
const reasonsPDF = risk.reasons.map(r => `
${r}`).join('');
pdfContent.innerHTML = `
Crowdfunding Risk Report: ${data.projectName}
Overall Risk Assessment
${risk.category}
Analysis Summary
${risk.advice}
Key Risk Factors
Summary of Inputs
This report is an automated assessment based on user-provided data and a simplified model. It is not financial advice.
`;
}
window.downloadPDF = async function() {
const pdfBtn = document.getElementById('pdfBtn');
if (!pdfBtn) return;
pdfBtn.innerText = "Generating...";
pdfBtn.disabled = true;
try {
const { jsPDF } = window.jspdf;
const pdfContent = document.getElementById('pdf-content');
pdfContent.classList.remove('invisible');
const canvas = await html2canvas(pdfContent, { scale: 2 });
pdfContent.classList.add('invisible');
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save(`Crowdfunding_Risk_Report_${getFormData().projectName.replace(/\s+/g, '_')}.pdf`);
} catch (error) {
console.error("PDF generation failed:", error);
alert("Sorry, there was an error creating the PDF.");
} finally {
pdfBtn.innerText = "Download PDF Report";
pdfBtn.disabled = false;
}
}
// --- START THE APP ---
initialize();
});