Estimated Variable APR Range (Starting): ${formatAprRange(baseVariableRange.low, baseVariableRange.high)}
Illustrative Repayment (using ${formatPercentSingle(midFixedApr,2)} fixed APR - mid-point of estimate):
Loan Amount: ${formatCurrency(loanAmountToRefinance)}
Loan Term: ${desiredLoanTermYears} years
Estimated Monthly Payment: ${formatCurrency(costs.monthlyPayment)}
Estimated Total Interest Paid: ${formatCurrency(costs.totalInterest)}
Estimated Total Repayment: ${formatCurrency(costs.totalPayments)}
Key Factors Influencing This Estimate:
${influencingFactors.map(f => `- ${f}
`).join('')}
Important Notes:
- These APR ranges are estimates and not guaranteed. Actual rates depend on lender underwriting, market conditions, and your complete financial profile.
- Variable rates can increase or decrease over time, affecting your monthly payment and total cost. They often have a lifetime cap.
- Refinancing federal student loans into a private loan means you will lose access to federal benefits such as Income-Driven Repayment plans, Public Service Loan Forgiveness (PSLF), and generous deferment/forbearance options. This is a critical consideration.
- Always compare offers from multiple lenders.
`;
resultsSectionEl.style.display = 'block';
}
function downloadPDF() {
if (!calculatorData.inputs || !calculatorData.estimatedFixedAPR) {
displayError("Please estimate your APR first."); return;
}
clearError();
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
displayError('PDF generation library (jsPDF core) is not loaded.'); return;
}
const JSPDFConstructor = window.jspdf.jsPDF;
const doc = new JSPDFConstructor('p', 'pt', 'a4');
if (typeof doc.autoTable !== 'function') {
displayError('PDF table plugin (jsPDF-AutoTable) is not functional.'); return;
}
const inputs = calculatorData.inputs;
const fixedApr = calculatorData.estimatedFixedAPR;
const varApr = calculatorData.estimatedVariableAPR;
const costs = calculatorData.illustrativeCosts;
let finalY = 40;
const pageWidth = doc.internal.pageSize.getWidth();
const margin = 40;
const contentWidth = pageWidth - 2 * margin;
doc.setFontSize(15);
doc.text("Graduate Loan Refinancing APR Estimate (U.S.)", pageWidth / 2, finalY, { align: 'center' });
finalY += 25;
doc.setFontSize(10);
const inputDataForPdf = [
["Credit Score Range:", inputs.creditScoreText],
["Annual Gross Income:", formatCurrency(inputs.annualIncome)],
["Monthly Debt Payments (excl. student loans):", formatCurrency(inputs.monthlyDebtPayments)],
["Calculated DTI:", formatPercentSingle(inputs.calculatedDTI,1)],
["Loan Amount to Refinance:", formatCurrency(inputs.loanAmountToRefinance)],
["Highest Degree Earned:", inputs.degreeLevelText],
["Desired New Loan Term:", `${inputs.desiredLoanTermYears} years`],
["Applying with Cosigner:", inputs.hasCosignerText]
];
doc.autoTable({
startY: finalY, head: [['Your Input Profile', 'Value']], body: inputDataForPdf, theme: 'grid',
headStyles: {fillColor: [0,115,170], fontSize:10}, styles: {fontSize: 9, cellPadding:3},
columnStyles: { 0: { fontStyle: 'bold', cellWidth: 200 } }
});
finalY = doc.lastAutoTable.finalY + 15;
if (finalY > doc.internal.pageSize.getHeight() - 120) { doc.addPage(); finalY = 40; }
doc.setFontSize(11);
doc.text("Estimated APR Ranges (Illustrative):", margin, finalY);
finalY += 15;
doc.setFontSize(9);
doc.text(`- Estimated Fixed APR Range: ${formatAprRange(fixedApr.low, fixedApr.high)}`, margin, finalY);
finalY += 12;
doc.text(`- Estimated Variable APR Range (Starting): ${formatAprRange(varApr.low, varApr.high)}`, margin, finalY);
finalY += 15;
if (costs && !isNaN(costs.monthlyPayment)) {
doc.setFontSize(11);
doc.text(`Illustrative Repayment (using ${formatPercentSingle(costs.aprUsed,2)} fixed APR):`, margin, finalY);
finalY += 15;
const costData = [
["Loan Amount:", formatCurrency(inputs.loanAmountToRefinance)],
["Loan Term:", `${inputs.desiredLoanTermYears} years`],
["Est. Monthly Payment:", formatCurrency(costs.monthlyPayment)],
["Est. Total Interest Paid:", formatCurrency(costs.totalInterest)],
["Est. Total Repayment:", formatCurrency(costs.totalPayments)]
];
doc.autoTable({
startY: finalY, body: costData, theme: 'plain', styles: {fontSize:9, cellPadding:2},
columnStyles: { 0: { fontStyle: 'bold'} }
});
finalY = doc.lastAutoTable.finalY + 15;
}
if (finalY > doc.internal.pageSize.getHeight() - 100) { doc.addPage(); finalY = 40; }
doc.setFontSize(10);
doc.text("Key Factors Influencing This Estimate:", margin, finalY);
finalY += 12;
doc.setFontSize(8);
calculatorData.influencingFactors.forEach(factor => {
const splitFactor = doc.splitTextToSize(`• ${factor}`, contentWidth);
doc.text(splitFactor, margin, finalY);
finalY += splitFactor.length * 9 + 2;
if (finalY > doc.internal.pageSize.getHeight() - 30 && calculatorData.influencingFactors.indexOf(factor) < calculatorData.influencingFactors.length -1) { doc.addPage(); finalY = 40; }
});
finalY += 5;
if (finalY > doc.internal.pageSize.getHeight() - 80) { doc.addPage(); finalY = 40; }
doc.setFontSize(10);
doc.text("Important Notes:", margin, finalY);
finalY += 12;
doc.setFontSize(8);
const notes = [
"- These APRs are estimates, not guaranteed rates. Actual offers vary.",
"- Variable rates can change, affecting payments and total cost.",
"- Refinancing U.S. federal loans into private loans means losing federal benefits (IDR, PSLF, etc.). This is a critical trade-off.",
"- Always compare offers from multiple lenders before making a decision."
];
notes.forEach(note => {
const splitNote = doc.splitTextToSize(`• ${note}`, contentWidth);
doc.text(splitNote, margin, finalY);
finalY += splitNote.length * 9 + 2;
if (finalY > doc.internal.pageSize.getHeight() - 30 && notes.indexOf(note) < notes.length -1) { doc.addPage(); finalY = 40; }
});
finalY+=5;
doc.setFontSize(7);
doc.setTextColor(150);
const disclaimerPdf = "Disclaimer: This tool provides illustrative estimates for U.S. private student loan refinancing. It is not financial advice. Consult lenders for actual rates and terms.";
const splitDisclaimer = doc.splitTextToSize(disclaimerPdf, contentWidth);
if (finalY > doc.internal.pageSize.getHeight() - 30) { doc.addPage(); finalY = 40; }
doc.text(splitDisclaimer, margin, finalY);
doc.save("Loan_Refinancing_APR_Estimate.pdf");
}
// Event Listeners
if (estimateAprButton) estimateAprButton.addEventListener('click', estimateAPR);
if (downloadPdfButton) downloadPdfButton.addEventListener('click', downloadPDF);
});