Home vs. Apartment Living Expense Comparison
Home Ownership Expenses (Monthly)
Enter monthly amount, or click 'Annual?' to enter yearly.
Enter monthly amount, or click 'Annual?' to enter yearly.
Apartment Living Expenses (Monthly)
Enter monthly amount, or click 'Annual?' to enter yearly.
E.g., Electricity, Gas (if separate), Internet.
Comparison Summary
Enter your estimated expenses in the 'Home Expenses' and 'Apartment Expenses' tabs. Then, results will be shown here.
Generated on: ${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}
`; pdfContentElement.innerHTML = pdfHTML; document.body.appendChild(pdfContentElement); // Must be in DOM for html2canvas try { const canvas = await html2canvas(pdfContentElement, { scale: 2, useCORS: true, backgroundColor: '#ffffff' }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const imgProps = pdf.getImageProperties(imgData); const imgWidth = imgProps.width; const imgHeight = imgProps.height; const ratio = Math.min((pdfWidth - 40) / imgWidth, (pdfHeight - 40) / imgHeight); // -40 for margins const scaledWidth = imgWidth * ratio; const scaledHeight = imgHeight * ratio; const xOffset = (pdfWidth - scaledWidth) / 2; const yOffset = 20; pdf.addImage(imgData, 'PNG', xOffset, yOffset, scaledWidth, scaledHeight); pdf.save('Home_vs_Apartment_Expenses.pdf'); } catch (error) { console.error("Error during PDF generation:", error); alert("An error occurred while generating the PDF."); } finally { document.body.removeChild(pdfContentElement); } }