Online OCR-Based Handwritten Notes to Digital Converter

Online OCR-Based Handwritten Notes to Digital Converter

Drag & drop your notes image here

or

Successfully extracted text from "${originalFile.name}".

`; showTab(1); }).catch(err => { console.error('OCR Error:', err); uploadStatus.innerHTML = `

An error occurred during text recognition.

`; }); }; // --- Download Logic --- downloadTxtButton.addEventListener('click', () => { downloadError.textContent = ''; // Clear previous errors // FIX: Check if originalFile exists before accessing its properties if (!originalFile) { downloadError.textContent = 'Please upload an image on the first tab before downloading.'; return; } const text = editableContent.value; const blob = new Blob([text], { type: 'text/plain' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `${originalFile.name.split('.')[0]}_digitized.txt`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); }); downloadPdfButton.addEventListener('click', () => { downloadError.textContent = ''; // Clear previous errors // FIX: Check if originalFile exists before accessing its properties if (!originalFile) { downloadError.textContent = 'Please upload an image on the first tab before downloading.'; return; } const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const margin = 20; const pageWidth = doc.internal.pageSize.getWidth(); const usableWidth = pageWidth - margin * 2; let y = margin; doc.setFont('helvetica', 'bold').setFontSize(18).text('Handwritten Note Conversion Report', pageWidth / 2, y, { align: 'center' }); y += 10; doc.setFontSize(10).setFont('helvetica', 'normal').setTextColor('#6B7280').text(`Original File: ${originalFile.name}`, pageWidth / 2, y, { align: 'center' }); y += 15; doc.setDrawColor('#E5E7EB').line(margin, y, pageWidth - margin, y); y += 10; // Add Original Image doc.setFontSize(14).setFont('helvetica', 'bold').setTextColor('#374151').text('Original Image', margin, y); y += 8; try { const imgData = originalImagePreview.src; const imgProps = doc.getImageProperties(imgData); const imgHeight = (imgProps.height * usableWidth) / imgProps.width; if (y + imgHeight > doc.internal.pageSize.getHeight() - margin) { doc.addPage(); y = margin; } doc.addImage(imgData, 'PNG', margin, y, usableWidth, imgHeight); y += imgHeight + 10; } catch (e) { console.error("Error adding image to PDF:", e); y += 6; } // Add Digitized Text if (y + 20 > doc.internal.pageSize.getHeight() - margin) { doc.addPage(); y = margin; } doc.setDrawColor('#E5E7EB').line(margin, y, pageWidth - margin, y); y += 10; doc.setFontSize(14).setFont('helvetica', 'bold').setTextColor('#374151').text('Digitized & Edited Text', margin, y); y += 8; doc.setFontSize(11).setFont('helvetica', 'normal').setTextColor('#4B5563'); const text = editableContent.value; const splitText = doc.splitTextToSize(text, usableWidth); doc.text(splitText, margin, y); doc.save(`${originalFile.name.split('.')[0]}_report.pdf`); }); // --- Initial Setup --- showTab(0); });
Scroll to Top