Annotation Format Converter
Annotation Preview
Conversion Results
${key}: ${value}
`) .join(''); } // Download handling function enableDownload(data, format) { downloadBtn.disabled = false; downloadBtn.onclick = function() { let blob, filename; if (format === 'coco' || format === 'voc') { blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }); filename = `annotations.${format === 'coco' ? 'json' : 'xml'}`; } else { blob = new Blob([data], { type: 'text/plain' }); filename = `annotations.${format === 'csv' ? 'csv' : 'txt'}`; } const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }; } // PDF Generation function generatePDF() { if (typeof jsPDF === 'undefined') { alert('PDF library is still loading. Please try again in a moment.'); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Add title doc.setFontSize(18); doc.setTextColor(40, 40, 40); doc.text('Annotation Conversion Report', 10, 15); // Add conversion details doc.setFontSize(12); const inputFormat = document.getElementById('inputFormat').value.toUpperCase(); const outputFormat = document.getElementById('outputFormat').value.toUpperCase(); doc.text(`Conversion: ${inputFormat} → ${outputFormat}`, 10, 25); // Add stats const statsText = conversionStats.innerText; const statsLines = statsText.split('\n').filter(line => line.trim() !== ''); let yPosition = 35; statsLines.forEach(line => { doc.text(line, 10, yPosition); yPosition += 7; }); // Add converted output (first 50 lines) doc.setFontSize(10); doc.text('Converted Annotations (sample):', 10, yPosition + 10); const outputLines = convertedOutput.textContent.split('\n').slice(0, 50); yPosition += 20; outputLines.forEach(line => { if (yPosition > 280) { doc.addPage(); yPosition = 20; } doc.text(line, 10, yPosition, { maxWidth: 180 }); yPosition += 7; }); // Add canvas image if available if (imageFileInput.files[0]) { const canvasDataURL = canvas.toDataURL('image/jpeg', 0.8); doc.addPage(); doc.addImage(canvasDataURL, 'JPEG', 10, 10, 180, 120); doc.text('Annotation Visualization', 10, 140); } // Save the PDF doc.save('Annotation_Conversion_Report.pdf'); } // Initialize document.addEventListener('DOMContentLoaded', function() { // Set up event listeners imageFileInput.addEventListener('change', function() { if (annotationFileInput.files[0]) { visualizeAnnotations(); } }); });