`;
let resultsSummaryHTML = `
`;
let scheduleTableHTML = '';
const scheduleTable = document.getElementById('posRewardScheduleBody');
if (scheduleTable && scheduleTable.rows.length > 0) {
scheduleTableHTML = `
`;
}
pdfContent.innerHTML = `
Calculation Summary
Estimated Total Rewards: ${rewardsTokens} ${tokenSymbol} (${rewardsUSD})
Total Balance After Staking: ${totalBalanceTokens} ${tokenSymbol} (${totalBalanceUSD})
Effective APY (after commission): ${effectiveAPY}%
Reward Schedule
| Period | Rewards This Period (${tokenSymbol}) | Total Rewards (${tokenSymbol}) | Total Balance (${tokenSymbol}) |
|---|
${inputSummaryHTML}
${resultsSummaryHTML}
${scheduleTableHTML}
`;
document.body.appendChild(pdfContent); // Add to body to allow html2canvas to render it
// Apply PDF specific styles if necessary using classes defined in CSS
pdfContent.querySelectorAll('table').forEach(table => table.classList.add('pdf-table'));
pdfContent.querySelectorAll('h2').forEach(h => h.classList.add('pdf-section-title')); // Example if you had h2s for sections
// The main title will be rendered via text for better control if html2canvas struggles with complex styles
try {
await pdf.html(pdfContent, {
callback: function (doc) {
doc.save('PoS_Staking_Rewards_Report.pdf');
document.body.removeChild(pdfContent); // Clean up temp div
},
x: 15, // Margin X
y: 15, // Margin Y
width: 560, // A4 width in points minus margins (595 - 15 - 15)
windowWidth: pdfContent.scrollWidth, // Width of content to be rendered
html2canvas: {
scale: 0.7, // Adjust scale to fit content better if needed. Default is (A4 width in px / element width in px)
logging: false,
useCORS: true // If any images/external resources were used
},
margin: [30, 30, 30, 30] // top, right, bottom, left
});
} catch (error) {
console.error("Error generating PDF:", error);
alert("Could not generate PDF. " + error.message);
document.body.removeChild(pdfContent); // Clean up temp div
}
}
// Initialize the first tab on load
posOpenTab(null, 'posTabCalculator');
// Ensure reset form sets default values correctly
posResetForm();