Auto-Biography Creator
Craft the story of your life, one chapter at a time.
Your Autobiography
Your completed story will be displayed here.
The Beginning
The Chapters of Your Life
Wisdom & Aspirations
Review Your Story
Your life story has been compiled below. Read through, make any edits, and ensure it reads just the way you want it.
Your completed story will be displayed here.
'; autobioOutputContent.classList.add('italic', 'items-center', 'justify-center'); downloadPdfBtn.classList.add('hidden'); } showTab(0); } function downloadPdf() { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'portrait', unit: 'in', format: 'letter' }); const pageHeight = doc.internal.pageSize.getHeight(); const pageWidth = doc.internal.pageSize.getWidth(); const margin = 0.75; const maxLineWidth = pageWidth - margin * 2; let verticalOffset = margin; // --- PDF Helper Functions --- const addText = (text, options) => { if (verticalOffset + (options.fontSize / 72 * 2) > pageHeight - margin) { doc.addPage(); verticalOffset = margin; addHeader(); addFooter(); } doc.setFont(options.font || 'times', options.style || 'normal'); doc.setFontSize(options.fontSize || 12); doc.setTextColor(options.color || '#2D3748'); const lines = doc.splitTextToSize(text, maxLineWidth); doc.text(lines, margin, verticalOffset); verticalOffset += (lines.length * options.fontSize / 72) + (options.spacing || 0); }; const addHeader = () => { doc.setFontSize(9); doc.setFont('helvetica', 'italic'); doc.setTextColor('#A0AEC0'); doc.text(`${fullNameInput.value || 'Autobiography'}`, pageWidth - margin, margin, { align: 'right' }); } const addFooter = () => { const pageCount = doc.internal.getNumberOfPages(); doc.setFontSize(9); doc.setFont('helvetica', 'italic'); doc.setTextColor('#A0AEC0'); doc.text(`Page ${pageCount}`, pageWidth - margin, pageHeight - 0.5, { align: 'right' }); } // --- PDF Generation --- addHeader(); addFooter(); // Title doc.setFont('times', 'bold'); doc.setFontSize(24); doc.setTextColor('#2D3748'); doc.text(`The Autobiography of`, pageWidth / 2, verticalOffset, { align: 'center' }); verticalOffset += 0.3; doc.text(`${fullNameInput.value || 'An Individual'}`, pageWidth / 2, verticalOffset, { align: 'center' }); verticalOffset += 0.5; doc.setDrawColor('#A0AEC0'); doc.line(margin, verticalOffset, pageWidth - margin, verticalOffset); verticalOffset += 0.3; // --- Parse and Add Content --- const fullText = finalAutobioText.value; const chapters = fullText.split('==='); chapters.forEach(chapterText => { chapterText = chapterText.trim(); if (!chapterText) return; const lines = chapterText.split('\n'); const title = lines.shift().replace("CHAPTER", "\nChapter").trim(); const content = lines.join('\n').trim(); addText(title, { fontSize: 16, font: 'times', style: 'bold', spacing: 0.2 }); addText(content, { fontSize: 12, font: 'times', style: 'normal', spacing: 0.25 }); }); doc.save(`${(fullNameInput.value || 'My').replace(/ /g, '_')}_Autobiography.pdf`); } // --- Event Listeners --- tabs.forEach((tab, index) => { tab.addEventListener('click', () => showTab(index)); }); nextBtn.addEventListener('click', () => { if (currentTabIndex < totalInputTabs - 1) { if (currentTabIndex === 3) { // After reflections compileAutobiography(); } showTab(currentTabIndex + 1); } else if (currentTabIndex === 4) { // Finalize finalizeAndShow(); } }); prevBtn.addEventListener('click', () => { if (currentTabIndex > 1) { showTab(currentTabIndex - 1); } }); addEventBtn.addEventListener('click', addLifeEvent); downloadPdfBtn.addEventListener('click', downloadPdf); // --- Initial State --- showTab(currentTabIndex); addLifeEvent(); // Start with one event card });