Craft Your Magic Wand

Wand Specification Sheet

Components

Description

Wand Lore

(L)Length: ${length}

(F)Flexibility: ${flexibility}

${getIconPlaceholderForPdf(handle)}Handle: ${handle}

${getIconPlaceholderForPdf(tip)}Tip: ${tip.replace(' pointy', '').replace(' rounded', '')}

`; pdfDescriptionP.textContent = descriptionP.textContent; pdfLoreP.textContent = loreP.textContent; console.log("PDF content populated (with placeholders)."); // Show results outputArea.style.display = 'block'; downloadButton.disabled = false; customizeButton.disabled = false; console.log("Wand generated and displayed."); }); // --- PDF Download --- downloadButton.addEventListener('click', () => { if (outputArea.style.display === 'none' || !descriptionP.textContent) { console.error("Cannot download PDF: No wand generated yet."); alert("Please customize a wand first!"); return; } console.log("Download PDF button clicked."); const element = document.getElementById('wand-pdf-content'); if (!element) { console.error("PDF content container element not found!"); return; } // **Crucial Check:** Verify content before capture console.log('Verifying PDF content before generation. Desc:', pdfDescriptionP.textContent); console.log('PDF content innerHTML snippet:', element.innerHTML.substring(0, 500) + "..."); if (!pdfDescriptionP.textContent || !pdfLoreP.textContent) { // Check critical fields console.error("PDF content appears empty or incomplete. Aborting PDF generation."); alert("Error: PDF content is missing or incomplete. Please try generating again."); return; } const filename = `My_Magic_Wand_Specification.pdf`; const opt = { margin: [18, 15, 18, 15], // mm T, L, B, R filename: filename, image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, logging: false, useCORS: true, // --- DEBUG: Disable letterRendering temporarily if issues persist --- // letterRendering: true, }, jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' } }; // --- Simplified Visibility Toggle --- const originalVisibility = element.style.visibility; element.style.visibility = 'visible'; // Make visible in its current off-screen position console.log("Starting PDF generation for element:", element); // Add small delay to potentially allow rendering, might not be needed setTimeout(() => { html2pdf().set(opt).from(element).save().then(() => { console.log("PDF Generated:", filename); }).catch(err => { console.error("PDF generation failed:", err); alert("Sorry, there was an error creating the PDF. Please check the console (F12) for details."); }).finally(() => { // Always restore original styles console.log("Restoring original visibility for PDF content element."); element.style.visibility = originalVisibility; }); }, 50); // 50ms delay }); } // End initializeCustomizer })(); // IIFE
Scroll to Top