Academic Report Card Generator

Academic Report Card Generator

Generated Report Card

Student Details

Courses & Grades

Academic Report Card

Student: ${studentName}
Student ID: ${studentId}
Grade Level: ${gradeLevel}
Report Date: ${reportDate}
${tableRowsHTML}
Subject Grade (%) Comments

Summary

Unweighted GPA: ${gpa}
`; // 5. Inject into DOM and switch tab reportOutputWrapper.innerHTML = finalReportHTML; showTab('rc-tab-dashboard'); } // --- PDF Download Function --- function downloadPDF() { // Check if libraries are loaded if (typeof jspdf === 'undefined' || typeof html2canvas === 'undefined') { console.error('REPORT CARD TOOL: jsPDF or html2canvas is not loaded.'); alert('Error: PDF generation libraries failed to load.'); return; } const reportElement = document.getElementById('rc-output-wrapper'); if (reportElement.innerHTML.trim() === '') { alert('Please generate a report card first.'); return; } const originalBtnText = pdfDownloadBtn.textContent; pdfDownloadBtn.textContent = 'Generating...'; pdfDownloadBtn.disabled = true; try { html2canvas(reportElement, { scale: 2, // Improve resolution useCORS: true, backgroundColor: '#ffffff' }).then((canvas) => { const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; // Calculate dimensions // A4 size in points: 595.28 x 841.89 // We'll use pixels for simplicity based on canvas const pdfWidth = canvas.width; const pdfHeight = canvas.height; // Use dimensions from canvas for a 1:1 fit const doc = new jsPDF({ orientation: pdfWidth > pdfHeight ? 'landscape' : 'portrait', unit: 'px', format: [pdfWidth, pdfHeight] }); doc.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); doc.save('report-card.pdf'); pdfDownloadBtn.textContent = originalBtnText; pdfDownloadBtn.disabled = false; }).catch(err => { console.error('REPORT CARD TOOL: html2canvas error:', err); alert('An error occurred while capturing the report card.'); pdfDownloadBtn.textContent = originalBtnText; pdfDownloadBtn.disabled = false; }); } catch(e) { console.error('REPORT CARD TOOL: PDF generation failed.', e); alert('Error: Could not generate PDF.'); pdfDownloadBtn.textContent = originalBtnText; pdfDownloadBtn.disabled = false; } } // --- Utility Function --- function escapeHTML(str) { if (!str) return ''; return str.replace(/[&<>"']/g, function(match) { return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[match]; }); } // --- Attach Event Listeners --- addSubjectBtn.addEventListener('click', () => addSubjectRow()); generateBtn.addEventListener('click', generateReport); pdfDownloadBtn.addEventListener('click', downloadPDF); // --- Initial Setup --- showTab('rc-tab-dashboard'); // Start on dashboard updateNavButtons(); // Add US-relevant sample data addSubjectRow('English 10', '92', 'Excellent work on the literary analysis paper.'); addSubjectRow('Algebra I', '85', 'Good improvement in understanding linear equations.'); addSubjectRow('Biology', '88', 'Strong performance on the cell biology lab.'); addSubjectRow('US History', '90', 'Very insightful contributions to class discussions.'); });
Scroll to Top