Content Summary Generator
Distill any text into a concise, easy-to-read summary.
Enter Your Content
Generate & Refine Summary
Preview & Export
Summary Preview
Your generated summary will appear here.
.*?<\/p>/g, '')}`; } previewBodyEl.innerHTML = formattedHtml; }; const handleDownloadPdf = () => { if (!window.jspdf) { console.error('jsPDF not loaded.'); return; } const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pageW = pdf.internal.pageSize.getWidth(); const pageH = pdf.internal.pageSize.getHeight(); const margin = 50; const maxLineWidth = pageW - margin * 2; let cursorY = 0; // --- PDF Template: Clean Teal Theme --- // Header pdf.setFillColor(20, 184, 166); // Teal-500 pdf.rect(0, 0, pageW, 10, 'F'); pdf.setFillColor(240, 253, 250); // Teal-50 pdf.rect(0, 10, pageW, 80, 'F'); pdf.setFont('helvetica', 'bold').setFontSize(22).setTextColor(15, 23, 42); // Slate-900 pdf.text("Content Summary", pageW / 2, 60, { align: 'center' }); cursorY = 120; // Title of Source Document pdf.setFont('helvetica', 'normal').setFontSize(10).setTextColor(100, 116, 139); // Slate-500 pdf.text("Summary of:", margin, cursorY); cursorY += 15; pdf.setFont('helvetica', 'bold').setFontSize(14).setTextColor(13, 148, 136); // Teal-600 const titleText = contentTitleEl.value || 'Untitled Document'; const titleLines = pdf.splitTextToSize(titleText, maxLineWidth); pdf.text(titleLines, margin, cursorY); cursorY += titleLines.length * 14 + 20; pdf.setDrawColor(204, 251, 241); // Teal-100 pdf.setLineWidth(1); pdf.line(margin, cursorY, pageW - margin, cursorY); cursorY += 30; // Summary Body const summaryText = generatedSummaryEl.value || 'No summary was generated.'; const summaryLines = summaryText.split('\n'); const processLine = (line) => { const checkBreak = (h) => { if (cursorY + h > pageH - margin) { pdf.addPage(); cursorY = margin; } }; const trimmedLine = line.trim(); if (trimmedLine.startsWith('* ') || trimmedLine.startsWith('- ')) { const itemText = trimmedLine.substring(2); pdf.setFont('helvetica', 'normal').setFontSize(11).setTextColor(51, 65, 85); // Slate-600 const textLines = pdf.splitTextToSize(itemText, maxLineWidth - 15); checkBreak(textLines.length * 14); pdf.text('\u2022', margin, cursorY); // Bullet point pdf.text(textLines, margin + 15, cursorY); cursorY += textLines.length * 14 + 5; } else if (trimmedLine) { pdf.setFont('helvetica', 'normal').setFontSize(11).setTextColor(30, 41, 59); // Slate-700 const paraLines = pdf.splitTextToSize(trimmedLine, maxLineWidth); checkBreak(paraLines.length * 14); pdf.text(paraLines, margin, cursorY); cursorY += paraLines.length * 14 + 12; } }; summaryLines.forEach(processLine); // Footer const pageCount = pdf.internal.getNumberOfPages(); for(let i = 1; i <= pageCount; i++) { pdf.setPage(i); pdf.setFillColor(20, 184, 166); // Teal-500 pdf.rect(0, pageH - 15, pageW, 15, 'F'); pdf.setFont('helvetica', 'normal').setFontSize(9).setTextColor(255, 255, 255); pdf.text(`Page ${i} of ${pageCount}`, pageW - margin, pageH - 5, { align: 'right' }); } pdf.save(`Content-Summary-${(contentTitleEl.value || 'Untitled').replace(/\s+/g, '-')}.pdf`); }; // --- Event Listeners --- if (generateBtn) generateBtn.addEventListener('click', handleGenerateClick); if (downloadPdfBtn) downloadPdfBtn.addEventListener('click', handleDownloadPdf); });
