`;
aira_pdfOutputContainerEl.innerHTML = resultsHtml; // Display results on the page
aira_openTab({currentTarget: document.querySelector(`.aira-tab-button[onclick*="aira-tab3"]`)}, 'aira-tab3');
}
async function aira_downloadPDF() {
const resultsContent = document.getElementById('aira-resultsSummary'); // Capture the content from the displayed results
if (!resultsContent) {
alert("No results to download. Please calculate the analysis first.");
return;
}
if (typeof html2canvas === 'undefined' || typeof jsPDF === 'undefined') {
alert("PDF generation library not loaded. Please check your internet connection or contact support.");
return;
}
const pdfButton = document.getElementById('aira-pdfDownloadButton');
if(pdfButton) pdfButton.textContent = "Generating PDF...";
try {
const canvas = await html2canvas(resultsContent, {
scale: 2, // Improves quality
useCORS: true, // If there were any external images (not in this case)
logging: false
});
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({
orientation: 'p',
unit: 'mm',
format: 'a4'
});
const imgProps= pdf.getImageProperties(imgData);
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
let heightLeft = pdfHeight;
let position = 0;
pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, pdfHeight);
heightLeft -= pdf.internal.pageSize.getHeight();
while (heightLeft >= 0) {
position = heightLeft - pdfHeight;
pdf.addPage();
pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, pdfHeight);
heightLeft -= pdf.internal.pageSize.getHeight();
}
pdf.save('Alternative_Investment_Risk_Analysis.pdf');
} catch (error) {
console.error("Error generating PDF:", error);
alert("Could not generate PDF. See console for details.");
} finally {
if(pdfButton) pdfButton.textContent = "Download Report as PDF";
}
}
function aira_resetTool() {
if (aira_investmentNameEl) aira_investmentNameEl.value = "";
if (aira_investmentTypeEl) aira_investmentTypeEl.selectedIndex = 0;
if (aira_investmentAmountEl) aira_investmentAmountEl.value = "";
if (aira_expectedReturnEl) aira_expectedReturnEl.value = "";
if (aira_investmentHorizonEl) aira_investmentHorizonEl.value = "";
if (aira_marketVolatilityEl) aira_marketVolatilityEl.selectedIndex = 1; // Medium
if (aira_liquidityRiskEl) aira_liquidityRiskEl.selectedIndex = 2; // High
if (aira_complexityRiskEl) aira_complexityRiskEl.selectedIndex = 1; // Medium
if (aira_valuationUncertaintyEl) aira_valuationUncertaintyEl.selectedIndex = 1; // Medium
if (aira_regulatoryRiskEl) aira_regulatoryRiskEl.selectedIndex = 1; // Medium
if (aira_counterpartyRiskEl) aira_counterpartyRiskEl.selectedIndex = 1; // Medium
if (aira_customNotesEl) aira_customNotesEl.value = "";
if (aira_pdfOutputContainerEl) aira_pdfOutputContainerEl.innerHTML = "
Please complete the previous steps to view the analysis.
"; aira_openTab({currentTarget: document.querySelector(`.aira-tab-button[onclick*="aira-tab1"]`)}, 'aira-tab1'); // Clear any existing risk profile styling if it was directly on the tab or container }