SEVERITY: ${entry.severity}/10
`;
logContainer.insertAdjacentHTML('beforeend', entryHtml);
});
}
function generatePdf() {
pdfLoader.classList.remove('hidden');
downloadPdfBtn.disabled = true;
const pdfContent = document.getElementById('pdf-log-output');
html2canvas(pdfContent, { scale: 2, windowWidth: pdfContent.scrollWidth, windowHeight: pdfContent.scrollHeight }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({
orientation: 'portrait',
unit: 'pt',
format: '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 imgHeight = pdfWidth / ratio;
let heightLeft = imgHeight;
let position = 40; // top margin
pdf.addImage(imgData, 'PNG', 40, position, pdfWidth - 80, imgHeight);
heightLeft -= (pdfHeight - 80);
while (heightLeft >= 0) {
position = -heightLeft - 40;
pdf.addPage();
pdf.addImage(imgData, 'PNG', 40, position, pdfWidth - 80, imgHeight);
heightLeft -= pdfHeight;
}
pdf.save('food_symptom_log.pdf');
pdfLoader.classList.add('hidden');
downloadPdfBtn.disabled = false;
}).catch(err => {
console.error("PDF generation failed:", err);
alert("Sorry, there was an error creating the PDF.");
pdfLoader.classList.add('hidden');
downloadPdfBtn.disabled = false;
});
}
});