Haiku Poetry Generator

Haiku Poetry Generator

Create a 5-7-5 syllable poem from a simple theme.

${line3}

`; haikuContent.innerHTML = haikuHTML; outputSection.classList.add('active'); // Store for PDF outputSection.dataset.line1 = line1; outputSection.dataset.line2 = line2; outputSection.dataset.line3 = line3; }; // --- PDF Generation --- const downloadPdf = () => { if (typeof window.jspdf === 'undefined') { console.error('jsPDF library not loaded'); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const line1 = outputSection.dataset.line1; const line2 = outputSection.dataset.line2; const line3 = outputSection.dataset.line3; const pageWidth = doc.internal.pageSize.getWidth(); const pageHeight = doc.internal.pageSize.getHeight(); // Add a subtle border doc.setDrawColor(200, 200, 200); doc.rect(10, 10, pageWidth - 20, pageHeight - 20); // Set custom font if available (jsPDF standard fonts are limited) // For simplicity, we use a standard font here. doc.setFont('times', 'italic'); // Center the text vertically and horizontally const yPos = pageHeight / 2 - 10; doc.setFontSize(22); doc.setTextColor(50, 50, 50); doc.text(line1, pageWidth / 2, yPos, { align: 'center' }); doc.setFontSize(26); doc.text(line2, pageWidth / 2, yPos + 15, { align: 'center' }); doc.setFontSize(22); doc.text(line3, pageWidth / 2, yPos + 30, { align: 'center' }); // Add a small footer doc.setFont('helvetica', 'normal'); doc.setFontSize(9); doc.setTextColor(150); doc.text('Generated by the Haiku Poetry Generator', pageWidth / 2, pageHeight - 15, { align: 'center' }); doc.save('haiku-poem.pdf'); }; // --- Event Listeners --- generateBtn.addEventListener('click', generateHaiku); downloadPdfBtn.addEventListener('click', downloadPdf); });
Scroll to Top