const Tesseract = require('tesseract.js');
// URL of the image to process
const imageUrl = [[FILE_JPG]];
// Array to store log messages
const logs = [];
// Function to add a log message
function addLog(message) {
logs.push(message);
}
// Function to display all logs
function displayLogs() {
logs.forEach(log => console.log(log));
}
await (new Promise((resolve, reject) => {
// Function to perform OCR (asynchronous operation)
async function performOCR(url) {
addLog('Starting OCR process.');
try {
const result = await Tesseract.recognize(url, 'eng', {
logger: m => addLog(m.status + ' ' + Math.round(m.progress * 100) + '%')
});
// Handle OCR result
addLog('OCR Process Completed.');
addLog('Extracted Text: ' + result.data.text);
} catch (error) {
// Handle OCR error
addLog('An error occurred during OCR processing.');
addLog(error.toString());
}
resolve()
displayLogs(); // Display all logs at the end
}
// Call performOCR function asynchronously
performOCR(imageUrl);
}));