Online Symbolism & Themes Finder for Books

Online Symbolism & Themes Finder

Enter a book title to discover its key symbols and themes.

${heading}: ${paragraph}

`; }); return result; }; // 2. Format it nicely in the hidden PDF area pdfContentArea.innerHTML = `

${title}

Key Symbols

${formatForPdf(symbolismHTML)}

Major Themes

${formatForPdf(themesHTML)}

Character Analysis

${formatForPdf(charactersHTML)} `; // Temporarily show the element to allow html2canvas to render it pdfContentArea.style.display = 'block'; pdfContentArea.style.position = 'absolute'; pdfContentArea.style.left = '-9999px'; // Move it off-screen pdfContentArea.style.width = '800px'; // Set a fixed width for consistent rendering try { // 3. Use html2canvas to create an image of the content const canvas = await html2canvas(pdfContentArea, { scale: 2, // Increase scale for better quality useCORS: true }); const imgData = canvas.toDataURL('image/png'); // 4. Use jsPDF to create the PDF const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const imgWidth = canvas.width; const imgHeight = canvas.height; const ratio = imgWidth / imgHeight; let finalImgWidth = pdfWidth - 40; // with some margin let finalImgHeight = finalImgWidth / ratio; let heightLeft = finalImgHeight; let position = 20; // top margin pdf.addImage(imgData, 'PNG', 20, position, finalImgWidth, finalImgHeight); heightLeft -= pdfHeight; while (heightLeft > 0) { position = position - pdfHeight + 40; // move to next page with margins pdf.addPage(); pdf.addImage(imgData, 'PNG', 20, position, finalImgWidth, finalImgHeight); heightLeft -= pdfHeight; } // 5. Trigger the download const filename = `Literary-Analysis-${title.split('"')[1] || 'Book'}.pdf`.replace(/[^a-z0-9]/gi, '-').toLowerCase(); pdf.save(filename); } catch (error) { console.error("Failed to generate PDF:", error); alert("Sorry, there was an error creating the PDF file."); } finally { // Clean up by hiding the temporary area pdfContentArea.style.display = 'none'; pdfContentArea.innerHTML = ''; } } // --- Event Listeners --- findThemesBtn.addEventListener('click', () => { const title = bookTitleInput.value.trim(); if (title) { fetchBookAnalysis(title); } else { showError("Please enter a book title."); } }); // Allow pressing Enter to submit bookTitleInput.addEventListener('keypress', (event) => { if (event.key === 'Enter') { event.preventDefault(); // Prevent form submission if it's inside a form findThemesBtn.click(); } }); downloadPdfBtn.addEventListener('click', generatePdf); // Pre-populate with a US-relevant example bookTitleInput.value = "The Great Gatsby"; });
Scroll to Top