`;
}
// --- PDF Generation ---
function generatePdf() {
if (!reportData || !performanceChart) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'mm', 'a4');
const chartImage = performanceChart.toBase64Image();
const blockchain = elements.blockchain.value;
const volume = elements.txVolume.options[elements.txVolume.selectedIndex].text;
doc.setFont('helvetica', 'bold');
doc.setFontSize(18);
doc.text('Smart Contract Evaluation Report', 105, 20, { align: 'center' });
doc.autoTable({
startY: 30,
head: [['Parameter', 'Value']],
body: [
['Blockchain', blockchain],
['Simulated Volume', volume],
['Avg. Gas/Compute', reportData.metrics.avgGas],
['Avg. Execution Time', reportData.metrics.avgTime],
['Security Score', `${reportData.metrics.securityScore}/100`],
],
theme: 'striped'
});
doc.setFontSize(14);
doc.text('Performance Under Load', 14, doc.autoTable.previous.finalY + 15);
doc.addImage(chartImage, 'PNG', 15, doc.autoTable.previous.finalY + 20, 180, 80);
doc.setFontSize(14);
doc.text('Optimization Suggestions', 14, doc.autoTable.previous.finalY + 110);
const suggestionsBody = reportData.suggestions.map(s => [s]);
doc.autoTable({
startY: doc.autoTable.previous.finalY + 115,
head: [['Suggestion']],
body: suggestionsBody,
theme: 'grid'
});
doc.save(`contract-evaluation-report.pdf`);
}
initialize();
});
