`;
return html;
}
function slfe_getAnswerText(elementId) {
const el = document.getElementById(elementId);
if (!el) return "N/A";
if (el.tagName === "SELECT") return el.options[el.selectedIndex].text;
if (el.type === "checkbox") return el.checked ? "Yes" : "No";
if (el.type === "number") return el.value || "Not specified";
return el.value || "Not specified";
}
function slfe_generatePDF() {
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
alert('PDF generation library (jsPDF) is not loaded.'); return;
}
const JSPDF_CONSTRUCTOR = window.jspdf.jsPDF;
const tempDoc = new JSPDF_CONSTRUCTOR();
if (typeof tempDoc.autoTable !== 'function') {
alert('jsPDF AutoTable plugin is not loaded.'); return;
}
if (Object.keys(slfe_userData).length === 0) {
alert('Please complete the estimation first.'); return;
}
const doc = new JSPDF_CONSTRUCTOR();
const data = slfe_userData;
let yPos = 15;
const pageMargin = 15;
const pageWidth = doc.internal.pageSize.getWidth();
const usableWidth = pageWidth - (2 * pageMargin);
const primaryColor = [0, 123, 255];
const headingColor = [0, 86, 179];
const textColor = [52, 65, 84];
function addMainHeader(text) {
doc.setFontSize(16);
doc.setTextColor(primaryColor[0], primaryColor[1], primaryColor[2]);
doc.text(text, pageWidth / 2, yPos, { align: 'center' });
yPos += 12;
}
function addSectionHeader(text) {
if (yPos > doc.internal.pageSize.getHeight() - 30) { doc.addPage(); yPos = pageMargin; }
doc.setFontSize(13);
doc.setFont(undefined, 'bold');
doc.setTextColor(headingColor[0], headingColor[1], headingColor[2]);
doc.text(text, pageMargin, yPos);
yPos += 8;
doc.setFont(undefined, 'normal');
}
function addParagraph(text, indent = 0, fontSize = 9, color = textColor) {
doc.setFontSize(fontSize);
doc.setTextColor(color[0], color[1], color[2]);
const lines = doc.splitTextToSize(text, usableWidth - indent);
if (yPos + (lines.length * (fontSize * 0.4)) + 3 > doc.internal.pageSize.getHeight() - 20) { doc.addPage(); yPos = pageMargin;}
doc.text(lines, pageMargin + indent, yPos);
yPos += (lines.length * (fontSize * 0.4)) + 3; // Adjust line height
}
function addListItem(text, prefix = "• ") {
addParagraph(prefix + text, 5);
}
addMainHeader("Student Loan Forgiveness Eligibility Estimate");
addParagraph("Date: " + new Date().toLocaleDateString(), 0, 8);
yPos += 5;
// User Inputs Summary
addSectionHeader("Summary of Your Inputs:");
let inputsForPdf = [
["Selected Loan Types:", data.loanTypesText],
["Primary Forgiveness Goal:", data.primaryGoalText]
];
if (data.primaryGoal === 'pslf' || data.primaryGoal === 'general_check') {
inputsForPdf.push(["PSLF - Employer Type:", data.pslfEmployerText]);
inputsForPdf.push(["PSLF - Years of Service:", data.pslfYears != null ? data.pslfYears.toString() : "N/A"]);
inputsForPdf.push(["PSLF - On IDR Plan:", data.pslfRepaymentPlanText]);
}
if (data.primaryGoal === 'idr_forgiveness' || data.primaryGoal === 'general_check') {
inputsForPdf.push(["IDR - Currently on Plan:", data.idrOnPlanText]);
inputsForPdf.push(["IDR - Years of Payments:", data.idrYearsPayments != null ? data.idrYearsPayments.toString() : "N/A"]);
inputsForPdf.push(["IDR - Original Balance:", data.idrOriginalBalanceText]);
}
if (data.primaryGoal === 'teacher_forgiveness' || data.primaryGoal === 'general_check') {
inputsForPdf.push(["Teacher - 5 Yrs Service:", data.teacherServiceYearsText]);
inputsForPdf.push(["Teacher - Subject Area:", data.teacherSubjectText]);
}
inputsForPdf.push(["TPD Indicated:", data.tpd ? "Yes" : "No"]);
inputsForPdf.push(["Closed School Indicated:", data.closedSchool ? "Yes" : "No"]);
inputsForPdf.push(["Borrower Defense Indicated:", data.borrowerDefense ? "Yes" : "No"]);
inputsForPdf.push(["Perkins Loan & Service Indicated:", data.perkinsService ? "Yes" : "No"]);
doc.autoTable({
startY: yPos,
head: [['Factor', 'Your Input']],
body: inputsForPdf,
theme: 'grid',
headStyles: { fillColor: primaryColor, textColor: [255,255,255] },
styles: { fontSize: 9, cellPadding: 2, overflow: 'linebreak' },
columnStyles: { 0: { fontStyle: 'bold', cellWidth: usableWidth * 0.4 }, 1: { cellWidth: usableWidth * 0.6 } },
didDrawPage: function (hookData) { yPos = hookData.cursor.y ? hookData.cursor.y + 10 : pageMargin; }
});
yPos = doc.lastAutoTable.finalY ? doc.lastAutoTable.finalY + 10 : yPos;
// Eligibility Estimates from HTML (Simplified for PDF)
addSectionHeader("Potential Eligibility Estimates:");
const resultsContainer = document.getElementById('slfe-results-summary');
if (resultsContainer) {
const items = resultsContainer.querySelectorAll('.slfe-result-item');
items.forEach(item => {
if (yPos > doc.internal.pageSize.getHeight() - 40) { doc.addPage(); yPos = pageMargin; }
const title = item.querySelector('h4')?.textContent || "Program";
const statusLine = item.querySelector('p strong')?.parentElement.textContent || "Status not determined.";
doc.setFontSize(10);
doc.setFont(undefined, 'bold');
doc.text(title, pageMargin, yPos);
yPos += 5;
doc.setFont(undefined, 'normal');
addParagraph(statusLine, 5, 9);
const reasonsList = item.querySelectorAll('ul li');
if (reasonsList.length > 0) {
addParagraph("Considerations/Reasons:", 5, 9);
reasonsList.forEach(reasonItem => {
addListItem(reasonItem.textContent, " - ");
});
}
const actionLink = item.querySelector('p a');
if(actionLink){
addParagraph("Action: Verify full details at official StudentAid.gov resources.", 5, 9);
}
yPos += 3; // Space between programs
});
}
// Important Notes & Disclaimer
if (yPos > doc.internal.pageSize.getHeight() - 60) { doc.addPage(); yPos = pageMargin; }
addSectionHeader("Important Notes & Disclaimer:");
const disclaimerText = [
"This tool provides a preliminary estimate based on self-reported answers and simplified criteria. It is NOT an official determination of eligibility.",
"Student loan forgiveness programs have detailed rules that can change. Always refer to StudentAid.gov for the most current and complete information.",
"Specific actions, like certifying employment or applying for discharge, are required. This tool does not submit applications.",
"Consider consulting with a student loan professional for personalized advice."
];
doc.setFontSize(8);
doc.setTextColor(80,80,80);
disclaimerText.forEach(line => {
const lines = doc.splitTextToSize("• " + line, usableWidth - 5); // -5 for bullet
if (yPos + (lines.length * 4) > doc.internal.pageSize.getHeight() - 15) { doc.addPage(); yPos = pageMargin; }
doc.text(lines, pageMargin + 5, yPos);
yPos += (lines.length * 4) + 1;
});
doc.save("Student_Loan_Forgiveness_Estimate.pdf");
}
