Enterprise Local OCR Engine – Pro Edition
1. Raw Source Input Pipeline
Active Queued Documents:
2. Output & Downstream Text Editor
0
Characters
0
Words
1
Lines
0s
Proc Time
0%
Accuracy
Recent Local Session Extractions:
No records found in this browser storage session.
";
const source = header + textOutput.value.replace(/\n/g, "
") + footer;
wpotTriggerDownload(source, 'docx_extraction.doc', 'application/vnd.ms-word');
});document.getElementById('wpot-btn-dl-pdf').addEventListener('click', () => {
const element = document.createElement('pre');
element.style.padding = '30px';
element.style.fontFamily = 'Helvetica, Arial, sans-serif';
element.style.whiteSpace = 'pre-wrap';
element.innerText = textOutput.value || "Empty extraction content.";
const options = {
margin: 15,
filename: `local_ocr_${Date.now()}.pdf`,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
};
html2pdf().from(element).set(options).save();
});
}function wpotTriggerDownload(content, filename, contentType) {
const blob = new Blob([content], { type: contentType });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}// Engine executing localized OCR scans sequential matching Tesseract instance logic
async function wpotExecuteBatchOCR() {
if (wpotState.queue.length === 0) {
wpotToast("Queue is empty. Please feed or drag pictures first.");
return;
}runBtn.disabled = true;
progressBarContainer.style.display = 'block';
const lang = document.getElementById('wpot-opt-lang').value;
statusLog.innerText = "Initializing localized OCR libraries...";try {
// Spawn separate web-worker parameters matching standard fallback paths
const worker = await Tesseract.createWorker(lang, 1, {
logger: m => {
if (m.status === 'recognizing') {
const prog = Math.round(m.progress * 100);
progressBar.style.width = prog + '%';
statusLog.innerText = `Extracting matching text layers: ${prog}%`;
}
}
});// Iterate queued entries synchronously
for (let i = 0; i < wpotState.queue.length; i++) {
const item = wpotState.queue[i];
if (item.processedText) continue; // Skip processing already executed itemsstatusLog.innerText = `Processing batch file [${i+1}/${wpotState.queue.length}]: ${item.name}`;
wpotSelectQueueItem(i);const t0 = performance.now();
// OCR executes directly using preprocessed canvas matching modifications
const dataUrl = previewCanvas.toDataURL('image/png');
const ret = await worker.recognize(dataUrl);
const t1 = performance.now();item.processedText = ret.data.text;
item.confidence = Math.round(ret.data.confidence);
item.processingTime = Math.round((t1 - t0) / 1000);wpotUpdateQueueUI();
if (i === wpotState.activeIndex) {
textOutput.value = item.processedText;
wpotUpdateEditorLines();
wpotUpdateStats(item);
}
}await worker.terminate();
statusLog.innerText = "Batch conversion completed successfully.";
wpotToast("Extraction completed with absolute safety.");
wpotSaveHistory(wpotState.queue[wpotState.activeIndex]);} catch (err) {
statusLog.innerText = "Execution halted due to system faults.";
wpotToast("Error encountered: " + err.message);
} finally {
runBtn.disabled = false;
progressBarContainer.style.display = 'none';
}
}// Live Editor Text Metrics Sync Lines
function wpotInitEditorSync() {
textOutput.addEventListener('input', () => {
wpotUpdateEditorLines();
wpotUpdateStats();
});
}function wpotUpdateEditorLines() {
const val = textOutput.value;
const matches = val.split('\n');
let indexString = '';
for (let i = 1; i <= matches.length; i++) {
indexString += i + '
';
}
lineNumbers.innerHTML = indexString;
}function wpotUpdateStats(item = null) {
const val = textOutput.value;
const chars = val.length;
const words = val.trim() === '' ? 0 : val.trim().split(/\s+/).length;
const lines = val.split('\n').length;document.getElementById('wpot-stat-chars').innerText = chars;
document.getElementById('wpot-stat-words').innerText = words;
document.getElementById('wpot-stat-lines').innerText = lines;if (item) {
document.getElementById('wpot-stat-speed').innerText = item.processingTime + 's';
document.getElementById('wpot-stat-confidence').innerText = item.confidence + '%';
}
}function wpotSaveHistory(item) {
if (!item || !item.processedText) return;
const entry = {
id: Date.now(),
name: item.name,
snippet: item.processedText.substring(0, 45) + '...',
rawText: item.processedText
};
wpotState.history.unshift(entry);
if (wpotState.history.length > 5) wpotState.history.pop();
localStorage.setItem('wpot_ocr_history_recs', JSON.stringify(wpotState.history));
wpotLoadHistory();
}function wpotLoadHistory() {
const saved = localStorage.getItem('wpot_ocr_history_recs');
const tray = document.getElementById('wpot-history-tray');
if (saved) {
wpotState.history = JSON.parse(saved);
tray.innerHTML = '';
wpotState.history.forEach(item => {
const el = document.createElement('div');
el.className = 'wpot-history-item';
el.innerHTML = `
${item.name} - ${item.snippet}
`;
el.querySelector('button').addEventListener('click', () => {
textOutput.value = item.rawText;
wpotUpdateEditorLines();
wpotUpdateStats();
wpotToast("Archived record restored into editor workspace.");
});
tray.appendChild(el);
});
}
}})();