Corporate Income Tax:
${data.corp || 'N/A'} ${data.corp_type ? `(${data.corp_type})` : ''}
${data.corp === 'None' ? `
No state corporate income tax.
` : ''}
${data.corp && data.corp.includes('Gross Receipts') ? `
State levies a Gross Receipts Tax instead of/alongside a traditional corporate income tax.
` : ''}
Property Tax:
${data.property_note || 'Assessed and collected at the local level (county/city/school district). Rates vary significantly.'}
`;
// Show results
resultsContainer.classList.remove('stx-hidden');
downloadPdfButton.classList.remove('stx-hidden');
});
// --- PDF Download Logic ---
downloadPdfButton.addEventListener('click', function () {
const selectedStateName = stateSelect.options[stateSelect.selectedIndex].text;
if (!selectedStateName || selectedStateName === '-- Choose a State --') return;
downloadPdfButton.disabled = true;
downloadPdfButton.textContent = 'Generating PDF...';
const { jsPDF } = window.jspdf;
const pdfElement = resultsContainer; // Capture the results container
const canvasOptions = {
scale: 2,
useCORS: true,
logging: false,
backgroundColor: getComputedStyle(pdfElement).backgroundColor // Use computed style for accuracy
};
// Temporarily make the element fully visible for capture if needed
// pdfElement.style.display = 'block'; // Ensure it's visible if previously hidden
html2canvas(pdfElement, canvasOptions).then(canvas => {
try {
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 canvasWidth = canvas.width;
const canvasHeight = canvas.height;
const ratio = canvasHeight / canvasWidth;
let imgWidth = pdfWidth - 40; // Margins
let imgHeight = imgWidth * ratio;
let position = 20; // Top margin
// Check if height exceeds page height
if (imgHeight > pdfHeight - 40) {
imgHeight = pdfHeight - 40; // Fit to page height
imgWidth = imgHeight / ratio; // Adjust width proportionally
// Center horizontally if width is less than page width
position = (pdfWidth - imgWidth) / 2;
} else {
// Center horizontally
position = (pdfWidth - imgWidth) / 2;
}
pdf.addImage(imgData, 'PNG', position, 20, imgWidth, imgHeight); // Use calculated position for x
pdf.save(`Tax-Overview-${selectedStateName.replace(/\s+/g, '-')}.pdf`);
} catch (error) {
console.error("Error generating PDF:", error);
errorMessageDiv.textContent = "Error generating PDF. Please try again.";
errorMessageDiv.classList.remove('stx-hidden');
} finally {
// pdfElement.style.display = ''; // Restore original display style if modified
// Re-enable button
downloadPdfButton.disabled = false;
downloadPdfButton.textContent = 'Download Summary as PDF';
}
}).catch(error => {
console.error("html2canvas error:", error);
errorMessageDiv.textContent = "Could not render the content for PDF.";
errorMessageDiv.classList.remove('stx-hidden');
// pdfElement.style.display = ''; // Restore original display style if modified
// Re-enable button
downloadPdfButton.disabled = false;
downloadPdfButton.textContent = 'Download Summary as PDF';
});
}); // End PDF Button Click
}); // End DOMContentLoaded