AI-Powered Ad Copy Generator

Configure Your Ad

Tell the AI what you're promoting.

Your generated ad copy will appear here

Fill in the details on the left and click generate.

${ad.headline}

${ad.body.replace(/\n/g, '
')}

`; resultsContainer.innerHTML += cardHTML; }); // Prepare content for PDF, which should be clean let pdfHTML = `

Ad Copy for: ${product}

`; adVariants.forEach((ad, index) => { pdfHTML += `

Variant ${index + 1}

${ad.headline}

${ad.body.replace(/\n/g, '
')}

Call to Action: ${ad.cta}

`; }); pdfDownloadContainer.innerHTML = pdfHTML; showState('results'); } catch (error) { console.error("Error generating ad copy:", error); showState('error'); } finally { setButtonLoading(false); } }; const handlePdfDownload = () => { const { jsPDF } = window.jspdf; if (!window.html2canvas || !jsPDF) { console.error("jsPDF or html2canvas library not loaded."); return; } const contentToPrint = document.getElementById('pdfDownloadContainerForRender'); // Ensure it's visible for rendering, then hide contentToPrint.style.position = 'absolute'; contentToPrint.style.left = '-9999px'; contentToPrint.style.display = 'block'; contentToPrint.style.width = '800px'; // Set a fixed width for consistent rendering contentToPrint.style.padding = '20px'; contentToPrint.style.backgroundColor = 'white'; html2canvas(contentToPrint, { scale: 2, useCORS: true }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF('p', 'pt', 'a4'); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); const filename = (productNameInput.value.trim().replace(/[^a-z0-9]/gi, '_').toLowerCase() || 'ad_copy') + '.pdf'; pdf.save(filename); // Hide the container again contentToPrint.style.display = 'none'; }).catch(err => { console.error("PDF generation failed:", err); contentToPrint.style.display = 'none'; }); }; // --- Event Listeners --- generateBtn.addEventListener('click', generateAdCopy); downloadPdfBtn.addEventListener('click', handlePdfDownload); });
Scroll to Top