Case Study Copywriting Tool
Craft compelling success stories that convert.
Case Study Preview
PDF Export Style
Your case study will be assembled here. Fill out the fields in the previous tabs to see a preview.
`; } }; const navigateTab = (n) => { const newIndex = currentTab + n; if (newIndex >= 0 && newIndex < tabs.length) { showTab(newIndex); } }; const downloadPDF = () => { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const data = Array.from(document.querySelectorAll('input, textarea')).reduce((acc, input) => { if (input.id) acc[input.id] = input.value; return acc; }, {}); const theme = document.querySelector('input[name="theme"]:checked').value; const page = { width: doc.internal.pageSize.getWidth(), height: doc.internal.pageSize.getHeight() }; const margin = 50; let y = 0; // --- Theme Setup --- let colors, fonts; if (theme === 'modern') { colors = { bg: '#FFFFFF', primary: '#111827', secondary: '#6B7280', accent: '#374151'}; fonts = { main: 'helvetica', heading: 'helvetica' }; } else { // corporate colors = { bg: '#FFFFFF', primary: '#1E3A8A', secondary: '#4B5563', accent: '#3B82F6'}; fonts = { main: 'helvetica', heading: 'helvetica' }; } // --- Helper Function --- const addSection = (title, textContent, options = {}) => { if (!textContent) return; const textLines = doc.splitTextToSize(textContent, page.width - margin * 2 - (options.indent || 0)); const spaceNeeded = textLines.length * 15 + (title ? 40 : 15); if (y + spaceNeeded > page.height - margin) { doc.addPage(); y = margin; } if(title){ y += 25; doc.setFont(fonts.heading, 'bold'); doc.setFontSize(14); doc.setTextColor(colors.primary); doc.text(title, margin, y); y += 20; } doc.setFont(fonts.main, options.fontStyle || 'normal'); doc.setFontSize(10); doc.setTextColor(colors.secondary); doc.text(textLines, margin + (options.indent || 0), y); y += textLines.length * 14; }; // --- PDF Header --- y = margin; doc.setFont(fonts.heading, 'bold'); doc.setFontSize(22); doc.setTextColor(colors.primary); const headlineLines = doc.splitTextToSize(data.headline || "Case Study", page.width - margin * 2); doc.text(headlineLines, margin, y); y += headlineLines.length * 25; doc.setFont(fonts.main, 'normal'); doc.setFontSize(11); doc.setTextColor(colors.secondary); doc.text(`Client: ${data.clientName || 'N/A'} | Industry: ${data.clientIndustry || 'N/A'}`, margin, y); y += 15; doc.setDrawColor(colors.accent); doc.setLineWidth(1.5); doc.line(margin, y, page.width - margin, y); // --- PDF Body --- addSection('The Challenge', data.theProblem); addSection('The Stakes', data.theStakes); addSection('The Solution', data.ourApproach); addSection('Implementation', data.actionsTaken); addSection('Results', data.keyMetrics); // --- Testimonial Block --- if (data.testimonial) { const quoteText = `“${data.testimonial.replace(/”|“/g, '')}”`; const textLines = doc.splitTextToSize(quoteText, page.width - (margin * 2) - 30); const boxHeight = textLines.length * 14 + 30; if(y + boxHeight > page.height - margin){ doc.addPage(); y = margin; } y += 20; doc.setFillColor(theme === 'modern' ? '#F9FAFB' : '#EFF6FF'); doc.setDrawColor(theme === 'modern' ? '#E5E7EB' : '#BFDBFE'); doc.setLineWidth(1); doc.rect(margin, y, page.width - margin * 2, boxHeight, 'FD'); doc.setFont(fonts.main, 'italic'); doc.setFontSize(11); doc.setTextColor(colors.primary); doc.text(textLines, margin + 15, y + 20); } doc.save(`${(data.clientName || 'case-study').replace(/\s+/g, '-').toLowerCase()}.pdf`); }; // Event Listeners tabs.forEach((tab, index) => tab.addEventListener('click', () => showTab(index))); prevBtn.addEventListener('click', () => navigateTab(-1)); nextBtn.addEventListener('click', () => navigateTab(1)); downloadPdfBtn.addEventListener('click', downloadPDF); // Initialization showTab(0); });