`).join('');
downloadBtnContainer.classList.remove('hidden');
}
function createCopy(style, product, audience, benefit, cta) {
let text = '';
switch (style) {
case 'Problem-Oriented':
text = `Tired of missed deadlines and chaotic workflows?\n\nFor ${audience}, managing complex projects is a major challenge. ${product} is designed to solve that.\n\n${benefit}.\n\nReady to take control? ${cta} today.`;
break;
case 'Inquisitive':
text = `What if you could streamline your entire project workflow in one place?\n\n${product} helps ${audience} do just that. ${benefit}.\n\nSee how it works. ${cta}.`;
break;
case 'Benefit-Driven':
text = `${benefit}.\n\nThat's the power of ${product} for ${audience}. Stop juggling tools and start delivering results.\n\n${cta} to learn more.`;
break;
case 'Professional':
default:
text = `For ${audience} looking to enhance productivity and efficiency:\n\n${product} offers a robust solution to ${benefit.toLowerCase()}.\n\nDiscover the difference. ${cta}.`;
break;
}
return { style, text };
}
window.downloadPDF = () => {
const { jsPDF } = window.jspdf;
const pdfContainer = document.getElementById('pdf-render-container');
const adCards = resultsContainer.querySelectorAll('.ad-card');
if (!pdfContainer || adCards.length === 0) {
console.error("No ad copy to generate PDF for.");
return;
}
let cardsHtml = '';
adCards.forEach(card => {
const style = card.querySelector('.text-indigo-600').textContent;
const text = card.querySelector('.text-gray-800').innerHTML.replace(/
/gi, "\n"); cardsHtml += `
`;
});
const pdfContentHtml = `
`;
pdfContainer.innerHTML = pdfContentHtml;
const contentToCapture = document.getElementById('pdf-content');
if (!contentToCapture) return;
const productName = document.getElementById('productName')?.value.trim() || 'ad_copy';
const fileName = `linkedin_ad_copy_${productName.replace(/[^a-z0-9]/gi, '_').toLowerCase()}.pdf`;
html2canvas(contentToCapture, { scale: 2, useCORS: true, logging: false })
.then(canvas => {
const imgData = canvas.toDataURL('image/jpeg', 0.95);
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const imgProps = pdf.getImageProperties(imgData);
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
const ratio = imgProps.width / imgProps.height;
const scaledImgHeight = pdfWidth / ratio;
let heightLeft = scaledImgHeight;
let position = 0;
pdf.addImage(imgData, 'JPEG', 0, position, pdfWidth, scaledImgHeight);
heightLeft -= pdfHeight;
while (heightLeft > 0) {
position -= pdfHeight;
pdf.addPage();
pdf.addImage(imgData, 'JPEG', 0, position, pdfWidth, scaledImgHeight);
heightLeft -= pdfHeight;
}
pdf.save(fileName);
pdfContainer.innerHTML = '';
}).catch(error => {
console.error("Error generating PDF:", error);
pdfContainer.innerHTML = '';
});
};
// Generate a sample on load
generateAdCopy();
});
/gi, "\n"); cardsHtml += `
${style}
${text}
Generated LinkedIn Ad Copy
${cardsHtml}Generated by LinkedIn Ad Copy Generator
