Lab Report Generator

Lab Report Generator

Structure and create a formal laboratory report.

${data.objective || 'N/A'}

Hypothesis

${data.hypothesis || 'N/A'}

`; html += `

Materials and Method

Materials

${data.materials || 'N/A'}

Procedure

${data.procedure || 'N/A'}

`; html += `

Results

Observations

${data.observations || 'N/A'}

`; if (data.data.length > 0) { html += `

Data

    ${data.data.map(d => `
  • ${d.label}: ${d.value}
  • `).join('')}
`; } html += `

Discussion

${data.analysis || 'N/A'}

Conclusion

${data.conclusion || 'N/A'}

`; document.getElementById('generated-report-content').innerHTML = html; }; const downloadPdf = () => { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' }); const data = getReportData(); const pageW = doc.internal.pageSize.getWidth(); const pageH = doc.internal.pageSize.getHeight(); const margin = 20; let y = 0, pageNum = 1; const primaryColor = '#14532d'; // green-900 const textColor = '#3f3f46'; // zinc-700 const addHeaderFooter = () => { if (pageNum > 1) { doc.setFontSize(9).setTextColor('#a1a1aa'); doc.text(data.title, margin, 10); doc.text(`Page ${pageNum}`, pageW - margin, pageH - 10, { align: 'right' }); } }; // Title Page doc.setFont('times', 'bold').setFontSize(24).setTextColor(primaryColor).text(doc.splitTextToSize(data.title, pageW - margin * 2), pageW / 2, pageH / 2 - 20, { align: 'center' }); if(data.author) doc.setFont('times', 'normal').setFontSize(14).setTextColor(textColor).text(data.author, pageW / 2, pageH / 2 + 10, { align: 'center' }); if(data.date) { const formattedDate = new Date(data.date + 'T00:00:00').toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }); doc.setFontSize(12).text(formattedDate, pageW / 2, pageH / 2 + 20, { align: 'center' }); } // Content Pages doc.addPage(); pageNum++; addHeaderFooter(); y = margin + 5; const addSection = (title, content, subTitle = false) => { if (!content) return; const titleSize = subTitle ? 12 : 16; const contentSize = 11; const titleYInc = subTitle ? 6 : 8; const contentYInc = 5; const lines = doc.setFont('times', 'normal').setFontSize(contentSize).splitTextToSize(content, pageW - margin * 2); const requiredHeight = titleYInc + (lines.length * contentYInc); if (y + requiredHeight > pageH - margin) { doc.addPage(); pageNum++; addHeaderFooter(); y = margin + 5; } doc.setFont('times', 'bold').setFontSize(titleSize).setTextColor(primaryColor).text(title, margin, y); y += titleYInc; doc.setFont('times', 'normal').setFontSize(contentSize).setTextColor(textColor).text(lines, margin, y); y += (lines.length * contentYInc) + 5; }; addSection('Introduction', data.objective); addSection('Hypothesis', data.hypothesis, true); addSection('Materials and Method', ""); addSection('Materials', data.materials, true); addSection('Procedure', data.procedure, true); addSection('Results', ""); addSection('Qualitative Observations', data.observations, true); if (data.data.length > 0) { addSection('Quantitative Data', data.data.map(d => `${d.label}: ${d.value}`).join('\n'), true); } addSection('Discussion', data.analysis); addSection('Conclusion', data.conclusion, true); doc.save(`${data.title.replace(/\s+/g, '-')}-Lab-Report.pdf`); }; downloadPdfBtn.addEventListener('click', downloadPdf); // Initialize const today = new Date('2025-09-18T00:00:00'); document.getElementById('experiment-date').value = today.toISOString().split('T')[0]; addDataPoint(); updateTabUI(0); lucide.createIcons(); });
Scroll to Top