Automated Document Summarizer

Automated Document Summarizer

Generated on: ${new Date().toLocaleDateString("en-US")}

${summaryData.originalWordCount}
Original Words
${summaryData.summaryWordCount}
Summary Words
${Math.round(reduction > 0 ? reduction : 0)}%
Content Reduction

Generated Summary

${summaryData.summaryText}

`; const pdfTemplate = document.getElementById('pdf-template'); pdfTemplate.innerHTML = reportHtml; pdfTemplate.style.position = 'absolute'; pdfTemplate.style.left = '-9999px'; pdfTemplate.classList.remove('invisible'); try { const { jsPDF } = window.jspdf; const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-report-container'), { scale: 2, backgroundColor: '#ffffff', useCORS: true }); 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('Document_Summary_Report.pdf'); } catch(e) { console.error(e); // Use a non-blocking notification instead of alert showNotification('Error generating PDF.', 'error'); } finally { pdfTemplate.style.position = ''; pdfTemplate.style.left = '-left-full'; pdfTemplate.classList.add('invisible'); button.disabled = false; button.textContent = originalText; } } function showNotification(message, type = 'success') { const notification = document.createElement('div'); notification.textContent = message; notification.className = 'fixed bottom-5 right-5 p-4 rounded-lg shadow-lg text-white'; notification.className += type === 'error' ? ' bg-red-600' : ' bg-green-600'; document.body.appendChild(notification); setTimeout(() => { notification.remove(); }, 3000); } // --- Event Listeners --- summarizeBtn.addEventListener('click', generateSummary); downloadPdfBtn.addEventListener('click', generatePdfReport); });
Scroll to Top