Total Size
${totalSizeMB} MB
Most Common Type
${mostCommonFileType}
Document Details
| File Name |
Type |
Author |
Size (KB) |
Last Modified |
`;
documentData.forEach(doc => {
dashboardHTML += `
| ${doc.name} |
${doc.type} |
${doc.author} |
${doc.size.toLocaleString()} |
${doc.modified} |
`;
});
dashboardHTML += `
`;
dashboardOutput.innerHTML = dashboardHTML;
}
/**
* Handles the PDF download functionality.
*/
function downloadPDF() {
const { jsPDF } = window.jspdf;
const documentItems = document.querySelectorAll('.document-item');
if (documentItems.length === 0) {
console.warn("No data to export.");
return;
}
const doc = new jsPDF();
const tableData = Array.from(documentItems).map(item => {
const inputs = item.querySelectorAll('input, select');
return [
inputs[0].value || '', // File Name
inputs[1].value || '', // File Type
inputs[2].value || '', // Author
parseFloat(inputs[3].value || 0).toLocaleString(), // File Size
inputs[4].value || '', // Creation Date
inputs[5].value || '' // Last Modified
];
});
doc.setFontSize(18);
doc.text('Document Metadata Analysis Report', 14, 22);
doc.setFontSize(11);
doc.setTextColor(100);
doc.text(`Report generated on: ${new Date().toLocaleDateString()}`, 14, 30);
doc.autoTable({
head: [['File Name', 'Type', 'Author', 'Size (KB)', 'Created', 'Last Modified']],
body: tableData,
startY: 35,
theme: 'grid',
headStyles: { fillColor: [2, 132, 199] }, // Sky-600
});
doc.save('Document-Metadata-Analysis.pdf');
}
// --- Event Listeners ---
if (addDocumentBtn) {
addDocumentBtn.addEventListener('click', addDocumentForm);
}
if (downloadPdfBtn) {
downloadPdfBtn.addEventListener('click', downloadPDF);
}
// --- Initial Setup ---
updateNavButtons();
generateDashboard();
});