`;
inputsHtml += `
Cash-Out Refinance Scenario Inputs:
New Total Loan Amount: ${eac_formatCurrency(inputs.refi.newLoanAmount)}
New Refi Interest Rate: ${eac_formatPercentage(inputs.refi.newInterestRate,3)}
New Refi Term: ${eac_formatYears(inputs.refi.newLoanTermYears)}
Refi Closing Costs: ${eac_formatCurrency(inputs.refi.closingCosts)}
`;
let betterMonthlyPaymentPdf = "";
if (results.hel.totalMonthlyHousingPayment < results.refi.totalMonthlyHousingPayment) betterMonthlyPaymentPdf = "hel";
else if (results.refi.totalMonthlyHousingPayment < results.hel.totalMonthlyHousingPayment) betterMonthlyPaymentPdf = "refi";
let betterUpfrontCostsPdf = "";
if (results.hel.upfrontCosts < results.refi.upfrontCosts) betterUpfrontCostsPdf = "hel";
else if (results.refi.upfrontCosts < results.hel.upfrontCosts) betterUpfrontCostsPdf = "refi";
const comparisonTableHtml = `
| Feature | Home Equity Loan | Cash-Out Refinance |
| New Loan Amt (for cash/total) | ${eac_formatCurrency(results.hel.loanAmount)} (HEL) | ${eac_formatCurrency(results.refi.newLoanAmount)} (Total Refi) |
| Interest Rate on New Debt | ${eac_formatPercentage(inputs.hel.interestRate,3)} | ${eac_formatPercentage(inputs.refi.newInterestRate,3)} |
| Term for New Debt/Loan | ${eac_formatYears(inputs.hel.loanTermYears)} | ${eac_formatYears(inputs.refi.newLoanTermYears)} |
| Est. Monthly Pmt (New Debt/Refi) | ${eac_formatCurrency(results.hel.monthlyPayment)} | ${eac_formatCurrency(results.refi.monthlyPayment)} |
| Resulting Total Mthly Housing P&I |
${eac_formatCurrency(results.hel.totalMonthlyHousingPayment)} |
${eac_formatCurrency(results.refi.totalMonthlyHousingPayment)} |
| Upfront Closing Costs |
${eac_formatCurrency(results.hel.upfrontCosts)} |
${eac_formatCurrency(results.refi.upfrontCosts)} |
| Combined LTV Post-Transaction | ${eac_formatPercentage(results.hel.combinedLTV)} | ${eac_formatPercentage(results.refi.ltv)} |
| Total Interest on New Debt/Refi | ${eac_formatCurrency(results.hel.totalInterestPaid)} | ${eac_formatCurrency(results.refi.totalInterestPaid)} |
`;
const conclusionTextPdf = document.getElementById('eac_conclusion').innerText.replace("Based on your inputs: ", "");
const qualitativePdfHtml = document.getElementById('eac_qualitativeSummaryContainer').innerHTML
.replace(/
/g, '
').replace(/<\/h4>/g, '
')
.replace(//g, '
').replace(/|<\/span>/g,'') // remove spans from qualitative
.replace(//g, '').replace(/- /g, '
- ')
.replace(/class="pro"/g, 'style="color:#1e7e34;"').replace(/class="con"/g, 'style="color:#c82333;"');
const disclaimer_pdf = document.querySelector('#equityAccessComparator .eac-interpretation-note').innerText.replace("Important Considerations:", "").trim();
pdfContentEl.innerHTML = `
Home Equity Access: Loan vs. Cash-Out Refinance Analysis
I. Input Summary
${inputsHtml}
II. Comparative Financial Projections
${conclusionTextPdf}
III. Qualitative Considerations Summary
${qualitativePdfHtml}
Important Disclaimer: ${disclaimer_pdf.replace(/\n/g, "
").replace(/
`;
document.body.appendChild(pdfContentEl);
html2canvas(pdfContentEl, { scale: 2, useCORS: true, logging:true, windowWidth: pdfContentEl.scrollWidth, windowHeight: pdfContentEl.scrollHeight }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
let numPages = Math.ceil(canvas.height / ( (pdfHeight - 40) * (canvas.width / (pdfWidth - 40)) ) );
let pageCanvasHeight = (pdfHeight - 40) * (canvas.width / (pdfWidth - 40));
for (let i = 0; i < numPages; i++) {
if (i > 0) pdf.addPage();
let sourceY = i * pageCanvasHeight;
let sourceHeight = Math.min(pageCanvasHeight, canvas.height - sourceY);
const tempCanvas = document.createElement('canvas');
tempCanvas.width = canvas.width;
tempCanvas.height = sourceHeight;
const ctx = tempCanvas.getContext('2d');
ctx.drawImage(canvas, 0, sourceY, canvas.width, sourceHeight, 0, 0, canvas.width, sourceHeight);
const pageImgData = tempCanvas.toDataURL('image/png');
const pageImgHeight = (sourceHeight * (pdfWidth - 40)) / canvas.width;
pdf.addImage(pageImgData, 'PNG', 20, 20, pdfWidth - 40, pageImgHeight, undefined, 'FAST');
}
pdf.save('Home_Equity_Loan_vs_Refinance.pdf');
if(document.body.contains(pdfContentEl)) document.body.removeChild(pdfContentEl);
}).catch(err => {
console.error("EAC PDF Error:", err); alert("Error generating PDF. See console.");
if(document.body.contains(pdfContentEl)) document.body.removeChild(pdfContentEl);
});
}
document.addEventListener('DOMContentLoaded', function() {
eac_openTab({}, 'eac_tab_current_situation');
// Default some values for quicker testing
const homeValEl = document.getElementById('eac_currentHomeValue');
if(homeValEl && !homeValEl.value) homeValEl.value = '400000';
const mortBalEl = document.getElementById('eac_currentMortgageBalance');
if(mortBalEl && !mortBalEl.value) mortBalEl.value = '150000';
const mortRateEl = document.getElementById('eac_currentMortgageRate');
if(mortRateEl && !mortRateEl.value) mortRateEl.value = '3.5';
const remTermEl = document.getElementById('eac_currentMortgageRemainingTermYears');
if(remTermEl && !remTermEl.value) remTermEl.value = '20';
const cashOutEl = document.getElementById('eac_cashOutAmountDesired');
if(cashOutEl && !cashOutEl.value) cashOutEl.value = '50000';
const helRateEl = document.getElementById('eac_hel_interestRate');
if(helRateEl && !helRateEl.value) helRateEl.value = '8.0';
const helTermEl = document.getElementById('eac_hel_loanTermYears');
if(helTermEl && !helTermEl.value) helTermEl.value = '15';
const refiRateEl = document.getElementById('eac_refi_newInterestRate');
if(refiRateEl && !refiRateEl.value) refiRateEl.value = '6.5';
// Refi term defaults to 30 years via select
if (!document.getElementById('eac_currentHomeValue')) {
console.error("Critical input 'eac_currentHomeValue' not found.");
}
});