Sci-Fi Civilization Profile Creator

Generate unique alien or future human societies for your universe! Define the parameters below.

${generatedCivData.biology}

Unique Trait / Quirk:

${generatedCivData.trait}

`; resultsDiv.style.display = 'block'; pdfBtn.disabled = false; } // --- PDF Download Function --- function downloadPDF() { if (!generatedCivData || !generatedCivData.name) { alert("Please generate a civilization profile first."); return; } // Ensure jsPDF is loaded if (typeof jspdf === 'undefined' || typeof jspdf.jsPDF === 'undefined') { console.error("jsPDF library or jsPDF constructor is not loaded correctly."); alert("Error: PDF generation library failed to load. Please check internet connection or Elementor setup."); return; } const { jsPDF } = jspdf; const doc = new jsPDF(); // --- PDF Styling --- const primaryColor = '#4fc3f7'; // Light Blue const secondaryColor = '#90a4ae'; // Grey const textColor = '#01579b'; // Dark Blue Text const pageMargin = 15; const lineSpacing = 7; let currentY = pageMargin; const pageHeight = doc.internal.pageSize.height; const pageWidth = doc.internal.pageSize.width; // Helper to add text with page breaks function addTextToPDF(text, size, color, style = 'normal') { doc.setFont("helvetica", style); // Standard font for PDF doc.setFontSize(size); doc.setTextColor(color); const splitText = doc.splitTextToSize(text, pageWidth - pageMargin * 2); splitText.forEach(line => { if (currentY + lineSpacing > pageHeight - pageMargin) { doc.addPage(); currentY = pageMargin; // Reset font on new page doc.setFont("helvetica", style); doc.setFontSize(size); doc.setTextColor(color); } doc.text(line, pageMargin, currentY); currentY += lineSpacing; }); } function addHeadingPDF(text) { addTextToPDF(text.toUpperCase() + ":", 12, primaryColor, 'bold'); // Blue heading currentY += lineSpacing * 0.1; } function addParagraphPDF(text) { addTextToPDF(text, 10, textColor); currentY += lineSpacing * 0.5; // Space after paragraph } // --- PDF Content --- addTextToPDF(`Civilization Profile: ${generatedCivData.name}`, 16, primaryColor, 'bold'); currentY += lineSpacing * 1.5; addHeadingPDF("Government"); addParagraphPDF(generatedCivData.government); addHeadingPDF("Society & Values"); addParagraphPDF(generatedCivData.society); addHeadingPDF("Technological Level"); addParagraphPDF(generatedCivData.technology); addHeadingPDF("Biology & Appearance Hint"); addParagraphPDF(generatedCivData.biology); addHeadingPDF("Unique Trait / Quirk"); addParagraphPDF(generatedCivData.trait); // --- Save PDF --- const safeFileName = `civ_profile_${generatedCivData.name.replace(/[^a-z0-9]/gi, '_')}`.toLowerCase(); doc.save(`${safeFileName}.pdf`); } // --- Event Listeners --- if (generateBtn) { generateBtn.addEventListener('click', generateProfile); } else { console.error("Generate button not found! Check ID: civ-generate-btn-a1d8c"); } if (pdfBtn) { pdfBtn.addEventListener('click', downloadPDF); } else { console.error("PDF button not found! Check ID: civ-pdf-btn-a1d8c"); // Corrected ID check } })(); // Immediately invoke the function
Scroll to Top