Giovanni Palerma
Giovanni Palerma

Reputation: 83

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/

Upvotes: 0

Views: 5117

Answers (1)

user5734311
user5734311

Reputation:

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.)

Upvotes: 1

Related Questions