Attendees
Agenda
Discussion Summary
${discussion.replace(/\n/g, '
')}
Action Items
`;
documentPreview.innerHTML = previewHtml;
// Enable download button only if there's content
const isFormEmpty = !title || !date || !attendees || !agenda || !discussion;
downloadPdfBtn.disabled = isFormEmpty;
};
const handleDownloadPdf = () => {
const { jsPDF } = window.jspdf;
const contentToPrint = document.getElementById('document-preview');
// Temporarily remove box-shadow for cleaner PDF render
contentToPrint.style.boxShadow = 'none';
html2canvas(contentToPrint, {
scale: 2, // Higher resolution
useCORS: true
}).then(canvas => {
// Restore box-shadow after capture
contentToPrint.style.boxShadow = '0 4px 6px rgba(0,0,0,0.05)';
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF('p', 'mm', 'a4');
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
const canvasWidth = canvas.width;
const canvasHeight = canvas.height;
const ratio = canvasWidth / canvasHeight;
let imgWidth = pdfWidth;
let imgHeight = imgWidth / ratio;
// If content is taller than one page, split it
let heightLeft = imgHeight;
let position = 0;
pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
heightLeft -= pdfHeight;
while (heightLeft > 0) {
position = heightLeft - imgHeight;
pdf.addPage();
pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
heightLeft -= pdfHeight;
}
const fileName = `Meeting_Minutes_${document.getElementById('meeting-title').value.replace(/\s+/g, '_') || 'Untitled'}.pdf`;
pdf.save(fileName);
});
};
// --- EVENT LISTENERS ---
minutesForm.addEventListener('input', generatePreview);
downloadPdfBtn.addEventListener('click', handleDownloadPdf);
// --- INITIAL LOAD ---
generatePreview(); // Generate initial placeholder view
});