Giovanni Palerma Giovanni Palerma - 17 days ago 12
Javascript Question

tesseract.js sample code not working

I'm trying to make Tesseract.js working.

I have taken a very simple code from the web, apprarently declared as working, but it doesn't.

<html>
<head>
<script src='https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js'></script>
<title>Tesseract Test</title>
</head>
<body>
<label for="fileInput">Choose File to OCR:</label>
<input type="file" id="fileInput" name="fileInput"/>
<br />
<br />
<div id="document-content">
</div>
</body>
<script>
document.addEventListener('DOMContentLoaded', function(){
var fileInput = document.getElementById('fileInput');
fileInput.addEventListener('change', handleInputChange);
});

function handleInputChange(event){
var input = event.target;
var file = input.files[0];
console.log(file);
Tesseract.recognize(file)
.progress(function(message){
console.log(message);
})
.then(function(result){
var contentArea = document.getElementById('document-content');
console.log(result);
})
.catch(function(err){
console.error(err);
});
}
</script>
</html>


This is their main website: http://tesseract.projectnaptha.com/

Answer

Works for me, but I had to make this change:

.then(function(result) {
  var contentArea = document.getElementById('document-content');
  contentArea.innerHTML = result.text;
})

(The example you posted only logs to the console.)

Comments