`;
summaryHtml += ``;
summaryContent.innerHTML = summaryHtml;
};
downloadPdfBtn.addEventListener('click', () => {
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF.autoTable === 'undefined') return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'letter' });
const getValue = id => document.getElementById(id).value;
const page = { width: doc.internal.pageSize.getWidth(), margin: 72 };
let y = page.margin;
// Title Page
doc.setFont('times', 'bold');
doc.setFontSize(24);
doc.text('Competitor Product Analysis', page.width / 2, y, { align: 'center' });
y += 40;
doc.setFontSize(16);
doc.setFont('times', 'normal');
doc.text(`Prepared for: ${getValue('yourProduct')}`, page.width / 2, y, { align: 'center' });
y += 20;
doc.text(`Date: ${getValue('analysisDate')}`, page.width / 2, y, { align: 'center' });
// Feature Table
const head = [['Feature', getValue('yourProduct'), ...competitors.map(c => c.product)]];
const body = [];
featureTable.querySelectorAll('tbody tr').forEach(row => {
const rowData = [];
row.querySelectorAll('input, textarea').forEach(input => rowData.push(input.value));
body.push(rowData);
});
doc.addPage();
y = page.margin;
doc.setFont('times', 'bold');
doc.setFontSize(16);
doc.text('Feature Comparison', page.margin, y);
y += 20;
doc.autoTable({
startY: y,
head: head,
body: body,
theme: 'grid',
headStyles: { fillColor: [22, 163, 74] },
styles: { font: 'times', fontSize: 10 },
});
y = doc.autoTable.previous.finalY + 30;
// Market Positioning
doc.addPage();
y = page.margin;
doc.setFont('times', 'bold');
doc.setFontSize(16);
doc.text('Market Positioning', page.margin, y);
y += 20;
marketAnalysisContainer.querySelectorAll('.p-4').forEach(block => {
doc.setFont('times', 'bold');
doc.setFontSize(12);
doc.text(block.querySelector('h4').textContent, page.margin, y);
y += 15;
doc.setFont('times', 'normal');
doc.setFontSize(10);
const price = block.querySelector('.market-price').value;
const strengths = block.querySelector('.market-strengths').value;
const weaknesses = block.querySelector('.market-weaknesses').value;
let content = `Pricing: $${price}\n\nStrengths:\n${strengths}\n\nWeaknesses:\n${weaknesses}`;
let lines = doc.splitTextToSize(content, page.width - page.margin * 2);
doc.text(lines, page.margin, y, { lineHeightFactor: 1.5 });
y += lines.length * 10 * 1.5 + 20;
});
doc.save(`Competitor-Analysis-${getValue('yourProduct')}.pdf`);
});
// --- Initial Setup ---
document.getElementById('analysisDate').valueAsDate = new Date();
addCompetitorBlock();
switchTab('setup');
});
Competitors
- `;
competitors.forEach(c => summaryHtml += `
- ${c.name} (${c.product}) `); summaryHtml += `
