`;
} else if (inputs.feeMethod === 'fixed' && inputs.feeFixedValue !== undefined) {
// inputsHtml += `
Specified Fixed Amount: ${hlo_formatCurrency(inputs.feeFixedValue)}
`;
}
let resultsHtml = "";
if (inputs.feeMethod === 'range') {
resultsHtml = `
Low Estimate (${hlo_formatPercentage(HLO_TYPICAL_LOW_PERCENT)}): ${hlo_formatCurrency(results.lowEstimateFee)}
High Estimate (${hlo_formatPercentage(HLO_TYPICAL_HIGH_PERCENT)}): ${hlo_formatCurrency(results.highEstimateFee)}
`;
} else {
resultsHtml = `
Estimated Origination Fee: ${hlo_formatCurrency(results.estimatedFee)}
`;
}
const interpretationNote_pdf = document.querySelector('#originationFeeEstimator .hlo-interpretation-note').innerText.replace("Understanding Origination Fees (USA Context):", "").trim();
pdfContentEl.innerHTML = `
Home Loan Origination Fee Estimation (USA Focus)
Input Summary
${inputsHtml}
Estimated Fee(s)
${resultsHtml}
Understanding Origination Fees:${interpretationNote_pdf.replace(/\n/g, "
").replace(/
`;
document.body.appendChild(pdfContentEl);
html2canvas(pdfContentEl, { scale: 2, useCORS: true, logging:true }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdfWidth = pdf.internal.pageSize.getWidth();
pdf.addImage(imgData, 'PNG', 20, 20, pdfWidth - 40, 0, undefined, 'FAST');
pdf.save('Home_Loan_Origination_Fee_Estimate.pdf');
if(document.body.contains(pdfContentEl)) document.body.removeChild(pdfContentEl);
}).catch(err => {
console.error("HLOE PDF Error:", err); alert("Error generating PDF. See console.");
if(document.body.contains(pdfContentEl)) document.body.removeChild(pdfContentEl);
});
}
document.addEventListener('DOMContentLoaded', function() {
hlo_toggleFeeInputs();
// Set some defaults for quicker testing
const loanAmountEl = document.getElementById('hlo_loanAmount');
if (loanAmountEl && !loanAmountEl.value) loanAmountEl.value = '300000';
if (!document.getElementById('hlo_loanAmount')) {
console.error("Critical input 'hlo_loanAmount' not found.");
}
});