Business Report Writer

Business Report Writer

Effortlessly structure and generate professional business reports.

${sec.content}

`; } }); if (!hasContent) { inputs.reportOutput.innerHTML = `

Please go back and fill in at least one content section to generate the report.

`; inputs.pdfButtonContainer.style.display = 'none'; } else { inputs.reportOutput.innerHTML = reportHTML; inputs.pdfButtonContainer.style.display = 'block'; } }; const downloadPDF = () => { try { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const reportData = { title: inputs.reportTitle.value || 'Untitled Report', company: inputs.companyName.value || 'Company Name', author: inputs.authorName.value || 'Author Name', date: new Date(inputs.reportDate.value).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }), summary: inputs.executiveSummary.value, intro: inputs.introduction.value, findings: inputs.findings.value, conclusion: inputs.conclusion.value, }; const pageWidth = doc.internal.pageSize.getWidth(); const pageHeight = doc.internal.pageSize.getHeight(); const margin = 20; let cursorY = 0; // --- Title Page --- doc.setFontSize(26); doc.setFont('helvetica', 'bold'); doc.text(reportData.title, pageWidth / 2, pageHeight / 2 - 20, { align: 'center', maxWidth: pageWidth - margin * 2 }); doc.setFontSize(16); doc.setFont('helvetica', 'normal'); doc.text(reportData.company, pageWidth / 2, pageHeight / 2 + 10, { align: 'center' }); doc.setFontSize(12); doc.text(`Prepared by: ${reportData.author}`, pageWidth / 2, pageHeight / 2 + 30, { align: 'center' }); doc.text(`Date: ${reportData.date}`, pageWidth / 2, pageHeight / 2 + 38, { align: 'center' }); // --- Content Pages --- const addSection = (title, content) => { if (!content.trim()) return; const requiredSpace = 20; // Approx space for header + a few lines if (cursorY > pageHeight - requiredSpace) { doc.addPage(); cursorY = margin; } doc.setFont('helvetica', 'bold'); doc.setFontSize(16); doc.text(title, margin, cursorY); cursorY += 10; doc.setFont('helvetica', 'normal'); doc.setFontSize(11); const textLines = doc.splitTextToSize(content, pageWidth - margin * 2); textLines.forEach(line => { if (cursorY > pageHeight - 15) { // Check before printing each line doc.addPage(); cursorY = margin; } doc.text(line, margin, cursorY); cursorY += 6; // Line height }); cursorY += 10; // Space after section }; doc.addPage(); cursorY = margin; addSection('Executive Summary', reportData.summary); addSection('Introduction', reportData.intro); addSection('Findings / Analysis', reportData.findings); addSection('Conclusion & Recommendations', reportData.conclusion); doc.save(`${reportData.title.replace(/\s+/g, '_')}.pdf`); } catch (error) { console.error("Failed to generate PDF:", error); if (inputs.pdfButtonContainer && !inputs.pdfButtonContainer.querySelector('.error-msg')) { const errorMsg = document.createElement('p'); errorMsg.textContent = 'Sorry, the PDF could not be created.'; errorMsg.className = 'text-red-600 text-sm mt-2 error-msg'; inputs.pdfButtonContainer.appendChild(errorMsg); } } }; downloadPdfButton.addEventListener('click', downloadPDF); updateUI(); });
Scroll to Top