`;
container.insertAdjacentHTML('beforeend', planHtml);
});
}
function generateFinalPlan() {
gatherData();
const outputContainer = document.getElementById('pdp-output-container');
if(!outputContainer) return;
let finalHtml = `
`;
// Goals and Actions Output
if (pdpData.goals.length > 0) {
finalHtml += `
`;
});
} else {
finalHtml += `
Personal Development Plan
`; // SWOT Output finalHtml += `SWOT Analysis
Strengths
${pdpData.swot.strengths || 'N/A'}
Weaknesses
${pdpData.swot.weaknesses || 'N/A'}
Opportunities
${pdpData.swot.opportunities || 'N/A'}
Threats
${pdpData.swot.threats || 'N/A'}
Goals & Action Plan
`; pdpData.goals.forEach(goal => { finalHtml += `Goal: ${goal.description}
Category: ${goal.category} | Target Date: ${goal.date || 'N/A'}
| Action Step | Due Date |
|---|---|
| ${action.description} | ${action.date || 'N/A'} |
| No action steps defined. | |
Goals & Action Plan
No goals have been defined.
`; } outputContainer.innerHTML = finalHtml; } async function downloadPDF() { const { jsPDF } = window.jspdf; const content = document.getElementById('pdp-output-container'); if (!content) { alert("Could not find the content to generate PDF."); return; } try { const canvas = await html2canvas(content, { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const pdfWidth = 210; // A4 width in mm const imgHeight = canvas.height * pdfWidth / canvas.width; let pdfHeight = imgHeight; let position = 0; const pdf = new jsPDF('p', 'mm', 'a4'); if (imgHeight > 297) { // A4 height while (position < imgHeight) { pdf.addImage(imgData, 'PNG', 0, -position, pdfWidth, imgHeight); position += 290; // approx page height, leaving some margin if (position < imgHeight) { pdf.addPage(); } } } else { pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, imgHeight); } pdf.save("Personal-Development-Plan.pdf"); } catch (error) { console.error("Error generating PDF:", error); alert("An error occurred while generating the PDF."); } }