REIT Performance & Market Cycle Tracking Tool
Average Total Return (Illustrative): $0.00
Dividend Yield (Illustrative): 0.0%
Key Notes:
Market Cycle Context:
Typical Economic Indicators:
Market Cycle Definitions
REIT Performance & Market Cycle Report
Performance Insights
Market Cycle Context
REIT Sector Performance Across Cycles (Chart)
Dividend Yield (Illustrative): ${sectorPerf.dividendYield.toFixed(1)}%
Key Notes: ${sectorPerf.notes}
`; document.getElementById('pdfCycleDetails').innerHTML = `Description: ${cycleDetails.description}
Typical Economic Indicators: ${cycleDetails.economicIndicators}
`; // Get chart as image const chartCanvas = document.getElementById('reitPerformanceChart'); let chartImageURI = ''; if (chartCanvas && reitChartInstance) { try { chartImageURI = chartCanvas.toDataURL('image/png', 1.0); document.getElementById('pdfChartImage').src = chartImageURI; } catch(e) { console.error("Error converting chart to image:", e); document.getElementById('pdfChartImage').alt = "Chart image could not be generated."; } } else { document.getElementById('pdfChartImage').alt = "Chart not available."; } // Use html2canvas to render the prepared PDF content // Ensure the container is temporarily visible for html2canvas if it's completely hidden // However, we made it absolutely positioned off-screen, so it should be renderable. pdfReportContainer.style.display = 'block'; // Make it renderable by html2canvas temporarily try { const canvas = await html2canvas(pdfReportContainer, { scale: 2, // Higher scale for better quality PDF useCORS: true, // If any external images were used (not in this case for chart itself) backgroundColor: '#ffffff', // Ensure solid background logging: false }); const imgData = canvas.toDataURL('image/png'); const imgProps = pdf.getImageProperties(imgData); const pdfWidth = pdf.internal.pageSize.getWidth(); const pageHeight = pdf.internal.pageSize.getHeight(); const margin = 40; // pt const contentWidth = pdfWidth - (2 * margin); const imgHeight = (imgProps.height * contentWidth) / imgProps.width; let heightLeft = imgHeight; let position = margin; pdf.addImage(imgData, 'PNG', margin, position, contentWidth, imgHeight); heightLeft -= (pageHeight - (2 * margin)); while (heightLeft > 0) { position = margin - imgHeight + heightLeft; // Adjust position for subsequent pages pdf.addPage(); pdf.addImage(imgData, 'PNG', margin, position, contentWidth, imgHeight); heightLeft -= (pageHeight - (2 * margin)); } pdf.save(`REIT_Performance_Report_${selectedSector.replace(/\s/g, '_')}.pdf`); } catch (error) { console.error("Error generating PDF with html2canvas:", error); alert("Failed to generate PDF. Check console for details."); } finally { pdfReportContainer.style.display = 'none'; // Hide it again } }