Software Documentation Generator

Software Documentation Generator

Create professional documentation for your software projects.

${data.description}

`; if (data.prerequisites) html += `

Prerequisites

${data.prerequisites}
`; if (data.installation) html += `

Installation

${data.installation}
`; if (data.features.length > 0) { html += `

Features & Usage

`; data.features.forEach(f => { html += `

${f.name}

`; if (f.desc) html += `

${f.desc}

`; if (f.code) html += `
${f.code}
`; }); } if (!data.description && !data.prerequisites && !data.installation && data.features.length === 0) { inputs.docsOutput.innerHTML = `

Please go back and provide some project information to generate the documentation.

`; inputs.pdfButtonContainer.style.display = 'none'; } else { inputs.docsOutput.innerHTML = html.replace(/

/g, '

').replace(/

/g, '

'); inputs.pdfButtonContainer.style.display = 'block'; } }; const downloadPDF = () => { try { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const data = gatherData(); const pageWidth = doc.internal.pageSize.getWidth(); const pageHeight = doc.internal.pageSize.getHeight(); const margin = 15; let cursorY = 0; let pageNumber = 1; const addPageNumber = () => { doc.setFontSize(10); doc.text(`${pageNumber}`, pageWidth / 2, pageHeight - 10, { align: 'center' }); }; // Title Page doc.setFont('helvetica', 'bold'); doc.setFontSize(28); doc.text(data.name, pageWidth / 2, pageHeight / 2 - 20, { align: 'center' }); if (data.version) { doc.setFont('helvetica', 'normal'); doc.setFontSize(16); doc.text(`Version ${data.version}`, pageWidth / 2, pageHeight / 2 - 10, { align: 'center' }); } doc.setFontSize(12); doc.text(`Documentation generated on ${new Date().toLocaleDateString()}`, pageWidth / 2, pageHeight / 2 + 10, { align: 'center' }); addPageNumber(); // Content doc.addPage(); pageNumber++; cursorY = margin; const addSection = (title, content, isCode = false) => { if (!content || !content.trim()) return; if (cursorY > pageHeight - 30) { doc.addPage(); pageNumber++; cursorY = margin; } doc.setFont('helvetica', 'bold'); doc.setFontSize(16); doc.text(title, margin, cursorY); cursorY += 8; const textLines = doc.splitTextToSize(content, pageWidth - margin * 2); if(isCode) { const codeBgColor = '#f0f0f0'; // Light gray background for code doc.setFont('courier', 'normal'); doc.setFontSize(10); const rectHeight = textLines.length * 4.5 + 4; if (cursorY + rectHeight > pageHeight - margin) { doc.addPage(); pageNumber++; cursorY = margin; } doc.setFillColor(240, 240, 240); doc.rect(margin, cursorY - 2, pageWidth - margin * 2, rectHeight, 'F'); doc.setTextColor(0,0,0); doc.text(textLines, margin + 2, cursorY + 2); cursorY += rectHeight; } else { doc.setFont('helvetica', 'normal'); doc.setFontSize(11); doc.setTextColor(80,80,80); textLines.forEach(line => { if (cursorY > pageHeight - 15) { doc.addPage(); pageNumber++; cursorY = margin; addPageNumber(); } doc.text(line, margin, cursorY); cursorY += 6; }); } cursorY += 10; }; if (data.description) addSection('Description', data.description); if (data.prerequisites) addSection('Prerequisites', data.prerequisites, true); if (data.installation) addSection('Installation', data.installation, true); if (data.features.length > 0) { if (cursorY > pageHeight - 30) { doc.addPage(); pageNumber++; cursorY = margin; } doc.setFont('helvetica', 'bold'); doc.setFontSize(18); doc.text('Features & Usage', margin, cursorY); cursorY += 10; data.features.forEach(f => { addSection(f.name, f.desc); if(f.code) addSection('Example:', f.code, true); }); } // Add page numbers to all pages for (let i = 2; i <= pageNumber; i++) { doc.setPage(i); addPageNumber(); } doc.save(`${data.name.replace(/\s+/g, '_')}_Docs.pdf`); } catch (error) { console.error("Failed to generate PDF:", error); } }; downloadPdfButton.addEventListener('click', downloadPDF); addFeature(); // Add one feature block by default updateUI(); });

Scroll to Top