Essay Grading System

Essay Grading System

${gradingData.essayText}

`; document.getElementById('download-report-pdf').addEventListener('click', generatePdf); }; const switchToTab = (tabId) => { tabButtons.forEach(btn => btn.classList.toggle('active', btn.dataset.tab === tabId)); if (tabId === 'setup') renderSetupPanel(); else if (tabId === 'grade') renderGradePanel(); else if (tabId === 'report') renderReportPanel(); }; // --- PDF Generation --- const generatePdf = () => { const buildPdfHtml = () => { const date = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }); let totalScore = 0; let maxScore = 0; const rubricHtml = gradingData.rubric.map((item, index) => { const score = gradingData.grades[index] || 0; totalScore += score; maxScore += item.points; return `${item.name}${score} / ${item.points}`; }).join(''); return `

Essay Evaluation: ${gradingData.essayTitle}

Report generated on ${date}

Final Score: ${totalScore} / ${maxScore}

Score Breakdown

${rubricHtml}
CriterionScore

Overall Feedback

${gradingData.feedback || 'N/A'}

Submitted Essay

${gradingData.essayText}

`; }; pdfRenderContainer.innerHTML = buildPdfHtml(); html2canvas(pdfRenderContainer, { scale: 2, useCORS: true }) .then(canvas => { const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: 'a4' }); const imgData = canvas.toDataURL('image/png'); const pdfWidth = pdf.internal.pageSize.getWidth(); const ratio = canvas.width / canvas.height; const pdfHeight = pdfWidth / ratio; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); pdf.save(`Essay_Grade_${gradingData.essayTitle.replace(/\s+/g, '_')}.pdf`); }); }; // --- Initial Load --- switchToTab('setup'); });
Scroll to Top