SENTENCES
${analysisResults.sentenceCount}
AVG. LENGTH
${analysisResults.avgSentenceLength}
READABILITY
${analysisResults.readability}
Sentence Length Distribution
Analyzed Text
${analysisResults.sentenceDetails.map(s => `${s.text}`).join(' ')}
`;
const pdfTemplate = document.getElementById('pdf-template');
pdfTemplate.innerHTML = reportHtml;
pdfTemplate.classList.remove('invisible');
new Chart(document.getElementById('pdf-variation-chart'), { type: 'bar', data: variationChart.data, options: { ...variationChart.options, animation: { duration: 0 }, maintainAspectRatio: false } });
try {
const { jsPDF } = window.jspdf;
const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-page'), { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', 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('Sentence_Analysis_Report.pdf');
} catch (e) { console.error('PDF Generation Error:', e); } finally {
downloadPdfBtn.disabled = false;
downloadPdfBtn.textContent = 'Download Analysis Report';
pdfTemplate.classList.add('invisible');
pdfTemplate.innerHTML = '';
}
}
// --- EVENT LISTENERS ---
analyzeBtn.addEventListener('click', runAnalysis);
downloadPdfBtn.addEventListener('click', generatePdfReport);
// --- INITIALIZATION ---
// No tabs
});