African Kingdoms History Tool
Select a kingdom from the dropdown above to view its historical details.
Capital(s): ${kingdom.capital}
Notable Rulers/Figures: ${kingdom.rulers}
Key Achievements/Significance:
${achievementsHtml}Historical Overview:
${kingdom.overview}
`; } downloadPdfBtn.addEventListener('click', () => { if (!currentKingdom) { alert("Please select a kingdom first."); return; } if (typeof jsPDF === 'undefined' || typeof jsPDF.API === 'undefined' || typeof jsPDF.API.autoTable === 'undefined') { alert("PDF generation library (jsPDF or autoTable) not loaded. Please check your internet connection or ensure the CDN links are active."); console.error("jsPDF or jsPDF-AutoTable is not loaded."); return; } const { jsPDF: JSPDF } = window.jspdf; const doc = new JSPDF(); doc.setFontSize(18); doc.text(currentKingdom.name, 105, 20, null, null, "center"); doc.setFontSize(11); doc.setTextColor(100); doc.text(`Historical Information Document`, 105, 28, null, null, "center"); let yPos = 40; function addDetail(label, value, options = {}) { const splitValue = doc.splitTextToSize(String(value), options.maxWidth || 170); doc.setFontSize(12); doc.setFont(undefined, 'bold'); doc.text(label, 14, yPos); doc.setFont(undefined, 'normal'); doc.setFontSize(10); doc.text(splitValue, 14 + (options.valueOffset || 40), yPos); // Adjust valueOffset for better alignment if needed const lineCount = Array.isArray(splitValue) ? splitValue.length : 1; yPos += (lineCount * (options.lineHeight || 5)) + (options.marginBottom || 3); // Increase spacing after each item if (yPos > 270) { doc.addPage(); yPos = 20; } // Basic page break } function addSectionTitle(title) { doc.setFontSize(12); doc.setFont(undefined, 'bold'); doc.text(title, 14, yPos); yPos += 7; if (yPos > 270) { doc.addPage(); yPos = 20; } } function addParagraph(text) { const splitText = doc.splitTextToSize(text, 180); doc.setFontSize(10); doc.setFont(undefined, 'normal'); doc.text(splitText, 14, yPos); const lineCount = Array.isArray(splitText) ? splitText.length : 1; yPos += (lineCount * 5) + 5; if (yPos > 270) { doc.addPage(); yPos = 20; } } function addList(items) { doc.setFontSize(10); items.forEach(item => { const splitItem = doc.splitTextToSize(`• ${item}`, 175); // Indent bullet doc.text(splitItem, 18, yPos); // Start text after bullet const lineCount = Array.isArray(splitItem) ? splitItem.length : 1; yPos += (lineCount * 5) + 2; if (yPos > 270) { doc.addPage(); yPos = 20; } }); yPos += 3; // Extra space after list } addDetail("Period:", currentKingdom.period, {valueOffset: 20}); addDetail("Geographic Region:", currentKingdom.region, {valueOffset: 45}); addDetail("Capital(s):", currentKingdom.capital, {valueOffset: 28}); addDetail("Notable Rulers/Figures:", currentKingdom.rulers, {valueOffset: 55}); yPos += 5; // Add some space before sections if (yPos > 270) { doc.addPage(); yPos = 20; } addSectionTitle("Key Achievements/Significance:"); addList(currentKingdom.achievements); yPos += 2; // Add some space before sections if (yPos > 270) { doc.addPage(); yPos = 20; } addSectionTitle("Historical Overview:"); addParagraph(currentKingdom.overview); doc.save(`${currentKingdom.name.replace(/\s+/g, '_')}_History.pdf`); }); });