University GPA Calculator
Easily calculate your Grade Point Average (GPA) by entering your courses, their credit hours, and the grades you received. You can add as many courses as needed.
Total Grade Points: ${totalGradePoints.toFixed(2)}
Course Breakdown:
| Course Name | Credits | Grade | GPA Points | Total Points |
|---|---|---|---|---|
| ${course.name} | ${course.credits} | ${course.grade} | ${course.gpaPoints} | ${course.courseGradePoints} |
PDF generation failed. Library not loaded.
'; } return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); const resultArea = document.getElementById('resultArea'); // Retrieve stored data for PDF const calculatedGpa = resultArea.dataset.calculatedGpa || 'N/A'; const totalCredits = resultArea.dataset.totalCredits || 'N/A'; const totalGradePoints = resultArea.dataset.totalGradePoints || 'N/A'; const courseData = JSON.parse(resultArea.dataset.courseData || '[]'); const generationDate = new Date().toLocaleString(); let yOffset = 20; // Title doc.setFontSize(24); doc.setTextColor(44, 62, 80); doc.text("GPA Calculation Report", 105, yOffset, { align: 'center' }); yOffset += 20; // Summary doc.setFontSize(16); doc.setTextColor(46, 204, 113); /* Green */ doc.text(`Calculated GPA: ${calculatedGpa}`, 20, yOffset); yOffset += 10; doc.text(`Total Credits: ${totalCredits}`, 20, yOffset); yOffset += 10; doc.text(`Total Grade Points: ${totalGradePoints}`, 20, yOffset); yOffset += 20; // Course Breakdown Table doc.setFontSize(14); doc.setTextColor(51, 51, 51); doc.text("Course Breakdown:", 20, yOffset); yOffset += 10; const tableHeaders = ["Course Name", "Credits", "Grade", "GPA Points", "Total Points"]; const tableRows = courseData.map(course => [ course.name, course.credits, course.grade, course.gpaPoints, course.courseGradePoints ]); // AutoTable plugin (if needed, but for simple tables, manual is fine or use jsPDF built-in table) // jsPDF's built-in table generation: // This requires a bit more manual positioning for complex tables, // or using `jspdf-autotable` for more advanced features. // For simplicity, let's just write row by row in a structured way. // Set up table properties const startX = 20; const tableWidth = 170; const colWidths = [tableWidth * 0.35, tableWidth * 0.15, tableWidth * 0.15, tableWidth * 0.15, tableWidth * 0.20]; // Proportional widths // Draw table headers doc.setFontSize(10); doc.setFont(undefined, 'bold'); // Set font to bold for headers doc.setFillColor(209, 236, 241); // Light blue background for header doc.rect(startX, yOffset, tableWidth, 10, 'F'); // Draw filled rectangle for header background let currentX = startX; tableHeaders.forEach((header, index) => { const colWidth = colWidths[index]; doc.text(header, currentX + 2, yOffset + 7); // Add text with small padding currentX += colWidth; }); doc.setFont(undefined, 'normal'); // Reset font to normal yOffset += 10; // Move yOffset past header // Draw table rows doc.setFontSize(9); tableRows.forEach(row => { if (yOffset > 270) { // Check for page overflow (approx for A4) doc.addPage(); yOffset = 20; // Reset yOffset for new page // Redraw headers on new page doc.setFont(undefined, 'bold'); doc.setFillColor(209, 236, 241); doc.rect(startX, yOffset, tableWidth, 10, 'F'); currentX = startX; tableHeaders.forEach((header, index) => { const colWidth = colWidths[index]; doc.text(header, currentX + 2, yOffset + 7); currentX += colWidth; }); doc.setFont(undefined, 'normal'); yOffset += 10; } currentX = startX; row.forEach((cellData, index) => { const colWidth = colWidths[index]; doc.text(String(cellData), currentX + 2, yOffset + 7); currentX += colWidth; }); yOffset += 10; // Move yOffset for next row }); yOffset += 20; // Extra space after table if (yOffset > 270) { // Check again before footer doc.addPage(); yOffset = 20; } // Footer/Generated by info doc.setFontSize(9); doc.setTextColor(150, 150, 150); doc.text(`Report Generated: ${generationDate}`, 20, doc.internal.pageSize.height - 15); doc.text("GPA Calculator Tool", doc.internal.pageSize.width - 20, doc.internal.pageSize.height - 15, { align: 'right' }); doc.save("GPA_Report.pdf"); }