// PDF Comparison Tool JavaScript document.addEventListener('DOMContentLoaded', function() { const uploadForm = document.getElementById('uploadForm'); const loadingSection = document.getElementById('loadingSection'); const resultsSection = document.getElementById('resultsSection'); const errorSection = document.getElementById('errorSection'); const errorMessage = document.getElementById('errorMessage'); // Handle form submission uploadForm.addEventListener('submit', function(e) { e.preventDefault(); const formData = new FormData(uploadForm); const pdf1 = document.getElementById('pdf1').files[0]; const pdf2 = document.getElementById('pdf2').files[0]; // Validate files if (!pdf1 || !pdf2) { showError('Please select both PDF files.'); return; } if (!pdf1.name.toLowerCase().endsWith('.pdf') || !pdf2.name.toLowerCase().endsWith('.pdf')) { showError('Please select valid PDF files.'); return; } // Show loading showLoading(); hideError(); // Submit form via AJAX fetch('/upload', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { hideLoading(); if (data.success) { displayResults(data.results); } else { showError(data.error || 'An error occurred during comparison.'); } }) .catch(error => { hideLoading(); showError('Network error: ' + error.message); }); }); function showLoading() { loadingSection.style.display = 'block'; resultsSection.style.display = 'none'; errorSection.style.display = 'none'; } function hideLoading() { loadingSection.style.display = 'none'; } function showError(message) { errorMessage.textContent = message; errorSection.style.display = 'block'; resultsSection.style.display = 'none'; } function hideError() { errorSection.style.display = 'none'; } function displayResults(results) { resultsSection.style.display = 'block'; // Display visual comparison displayVisualComparison(results); // Display spelling issues displaySpellingIssues(results); // Display barcodes and QR codes displayBarcodes(results); } function displayVisualComparison(results) { const visualContent = document.getElementById('visualComparisonContent'); let html = '
No differences detected
' }No differences detected
' }No visual comparison data available.
| Word | Original | English Suggestions | French Suggestions |
|---|---|---|---|
| ${issue.word} | ${issue.original_word} |
${englishSuggestions} | ${frenchSuggestions} |
| Type | Data | Position |
|---|---|---|
| ${barcode.type} | ${barcode.data} |
${position} |