Public Service Announcement Template Generator

Public Service Announcement Template Generator

1. Core Message
2. Audience & Action
Add New Template

Use placeholders: {TOPIC}, {AUDIENCE}, {MESSAGE}, {CTA}, {SPONSOR}, {DATELINE}, {DATE}

My Current Templates

Template Name Action

No PSA templates found. Please add one in the "Template Configuration" tab.

'; return; } psaTemplates.forEach(template => { let psaText = template.text; // Replace all placeholders for (const [key, value] of Object.entries(data)) { psaText = psaText.replace(new RegExp(key, 'g'), value); } const card = document.createElement('div'); card.className = 'psa-review-card'; card.innerHTML = `

${template.name}

${psaText}
`; reviewArea.appendChild(card); }); switchTab(1); // Switch to review tab } function downloadPDF() { const { jsPDF } = window.jspdf; const doc = new jsPDF(); const pageHeight = doc.internal.pageSize.height; const pageWidth = doc.internal.pageSize.width; const margin = 20; const maxWidth = pageWidth - (margin * 2); let currentY = margin; doc.setFontSize(20); doc.setFont(undefined, 'bold'); doc.text("Public Service Announcement Drafts", pageWidth / 2, currentY, { align: 'center' }); currentY += 15; const reviewCards = reviewArea.querySelectorAll('.psa-review-card'); reviewCards.forEach(card => { const title = card.querySelector('h3').textContent; const text = card.querySelector('pre').textContent; const titleHeight = 10; const textLines = doc.splitTextToSize(text, maxWidth); const textHeight = textLines.length * 7 + 15; // 7 per line + padding if (currentY + titleHeight + textHeight > pageHeight - margin) { doc.addPage(); currentY = margin; } doc.setFontSize(16); doc.setFont(undefined, 'bold'); doc.text(title, margin, currentY); currentY += titleHeight; doc.setFontSize(11); doc.setFont('Courier', 'normal'); // Use monospace font for scripts/code doc.setDrawColor(200); doc.setLineWidth(0.5); doc.rect(margin, currentY - 2, maxWidth, textHeight - 10); // Draw box around script // Add padding for text inside the box let tempY = currentY + 5; textLines.forEach(line => { doc.text(line, margin + 5, tempY); tempY += 7; }); currentY += textHeight; }); doc.save('psa-drafts.pdf'); } // --- Tab Navigation --- function switchTab(tabIndex) { tabs.forEach((tab, index) => { tab.classList.toggle('active', index === tabIndex); contents[index].classList.toggle('active', index === tabIndex); }); currentTab = tabIndex; updateNavButtons(); } function updateNavButtons() { prevBtn.disabled = currentTab === 0; nextBtn.disabled = currentTab === tabs.length - 1; } tabs.forEach((tab, index) => { tab.addEventListener('click', () => switchTab(index)); }); nextBtn.addEventListener('click', () => { if (currentTab < tabs.length - 1) switchTab(currentTab + 1); }); prevBtn.addEventListener('click', () => { if (currentTab > 0) switchTab(currentTab - 1); }); // --- Event Listeners --- generateBtn.addEventListener('click', generateDrafts); configForm.addEventListener('submit', handleAddTemplate); pdfDownloadBtn.addEventListener('click', downloadPDF); // --- Initial Setup --- loadDefaultTemplates(); updateNavButtons(); });
Scroll to Top