`;
elements.resultsPlaceholder.classList.remove('hidden');
elements.resultsContainer.classList.add('hidden');
}
// --- PDF Generation ---
function generatePdf() {
if (extractedKeywords.length === 0 || !originalText) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFont('helvetica', 'bold');
doc.setFontSize(18);
doc.text("Keyword Extraction Report", doc.internal.pageSize.getWidth() / 2, 20, { align: 'center' });
doc.setFontSize(11);
doc.setTextColor(100);
doc.text(`Generated on: ${new Date().toLocaleDateString('en-US')}`, 14, 30);
doc.setFont('helvetica', 'bold');
doc.setFontSize(12);
doc.text("Original Text", 14, 45);
doc.setFont('helvetica', 'normal');
doc.setFontSize(10);
// Use splitTextToSize for word wrapping
const textLines = doc.splitTextToSize(originalText, doc.internal.pageSize.getWidth() - 28);
doc.text(textLines, 14, 52);
const tableBody = extractedKeywords.map(kw => [
kw.keyword,
kw.relevance.toFixed(2)
]);
doc.autoTable({
startY: doc.autoTable.previous ? doc.autoTable.previous.finalY + 15 : 75,
head: [['Keyword', 'Relevance Score']],
body: tableBody,
theme: 'striped',
headStyles: { fillColor: '#4338ca' }
});
doc.save(`keyword-extraction-report.pdf`);
}
initialize();
});
