Personalized Poetry Generator

Enter a topic and choose a mood and style to generate a simple poem!

Your personalized poem will appear here!

Crafting verses...

'; downloadBtn.style.display = 'none'; const generatedPoem = generatePoem(topic, mood, structure, length, keywords); // Use a
 tag within the results div to preserve whitespace from \n
         resultsDiv.innerHTML = `
${generatedPoem}
`; downloadBtn.style.display = 'block'; // Show download button }); document.getElementById('clearBtn').addEventListener('click', () => { document.getElementById('poemTopic').value = ''; document.getElementById('poemMood').value = 'any'; document.getElementById('poemStructure').value = 'freeverse'; document.getElementById('poemLength').value = 'short'; document.getElementById('poemKeywords').value = ''; document.getElementById('poemResults').innerHTML = '

Your personalized poem will appear here!

'; document.getElementById('downloadPdfBtn').style.display = 'none'; // Hide PDF button }); // Download PDF Button document.getElementById('downloadPdfBtn').addEventListener('click', () => { const resultsDiv = document.getElementById('poemResults'); const poemText = resultsDiv.textContent.trim(); // Get text content, which preserves line breaks from


        if (!poemText || poemText.includes('Your personalized poem will appear here!') || poemText.includes('Crafting verses...')) {
             alert("No poem to download.");
             return;
        }

        // --- PDF Generation ---
        const doc = new jsPDF();

        const margin = 15;
        let y = margin;
        const pageHeight = doc.internal.pageSize.height;
        const pageWidth = doc.internal.pageSize.width;
        const maxLineWidth = pageWidth - 2 * margin; // Max width for text line

        doc.setFontSize(18);
        doc.setTextColor(52, 58, 64); // Match text-color variable #343a0
        doc.text("Your Personalized Poem", margin, y);
        y += 15; // Space after title

        doc.setFontSize(12);
        doc.setTextColor(52, 58, 64); // Match text-color variable #343a0

         // Add the poem text, handling wrapping and preserving line breaks (\n)
         // jsPDF splitTextToSize handles wrapping, but we need to manually handle \n for line/stanza breaks
        const lines = poemText.split('\n'); // Split the entire text by newline characters

         lines.forEach(line => {
             // If a line is empty or just whitespace, treat it as a stanza break
              if (line.trim() === "") {
                  y += 7; // Add extra space for stanza break (estimate line height)
              } else {
                  const wrappedLines = doc.splitTextToSize(line, maxLineWidth);
                  wrappedLines.forEach(wrappedLine => {
                       if (y + 7 > pageHeight - margin) { // Estimate line height + padding
                           doc.addPage();
                           y = margin;
                           doc.setFontSize(18);
                           doc.setTextColor(52, 58, 64);
                           doc.text("Your Personalized Poem (cont.)", margin, y);
                           y += 15;
                           doc.setFontSize(12);
                           doc.setTextColor(52, 58, 64);
                       }
                       doc.text(wrappedLine, margin, y);
                       y += 7; // Estimate line height
                  });
              }
         });


        doc.save('personalized_poem.pdf');
    });

				

Key Features:

  1. Customizable Inputs: Users can input theme, mood, and keywords to generate unique poems.

  2. AI-Generated Poems: The tool creates beautiful and personalized poems based on user inputs.

  3. Centered Design: The tool is perfectly centered on the page, ensuring a clean and professional look.

  4. PDF Download: Users can download the generated poem as a PDF, complete with the same color scheme for consistency.

  5. Responsive Design: The tool is fully responsive and works seamlessly on all device

    Benefits for End Users:

    1. Creative Fun: Users can generate unique and personalized poems for entertainment or personal projects.

    2. Customizable Outputs: The tool allows users to tailor the generated poems based on specific traits.

    3. Educational Tool: Great for students and educators to explore creativity and poetic expression.

    4. Portable Results: The PDF download feature allows users to save and share their generated poems easily.

    5. User-Friendly Interface: The simple and intuitive design ensures that users of all ages and technical skill levels can use the tool effortlessly.

Scroll to Top