1. Products
  2.   OCR
  3.   JavaScript
  4.   Tesseract.js
 
  

Open Source JavaScript API for Adding OCR to Web Apps

A Free JavaScript library for integrating optical character recognition (OCR) functionality to Web Apps & Convert Images of Printed or Handwritten text into Machine-readable Text

Tesseract.js is a very useful open-source JavaScript library that enables software developers to integrate optical character recognition (OCR) functionality inside their web applications with minimum effort and cost. OCR is the process of converting images of printed or handwritten text into machine-readable text. Tesseract.js is a port of the popular Tesseract OCR engine, which was originally developed by Hewlett-Packard in the 1980s and later maintained by Google. Tesseract.js can recognize over 100 languages, making it a powerful tool for developers looking to add OCR functionality to their web applications.

Tesseract.js is very easy to handle and can be used for a variety of tasks, such as extracting text from scanned documents, receipts, and business cards, automating data entry tasks as well as enhancing search functionality within web applications. One of the key advantages of Tesseract.js is its ability to recognize text even when the input image is of poor quality or resolution. The library uses machine learning algorithms to improve the accuracy of OCR results. It can also perform page layout analysis and detect regions of interest within an image.

Tesseract.js is getting popular due to its ease of use as well as powerful OCR capabilities and can be smoothly run either in a browser or on a server with NodeJS. It provides a simple API that allows software developers to configure OCR options such as language, page segmentation mode, and whitelist characters. Its ability to recognize text from poor quality images and support for multiple languages make it a valuable tool for a wide range of applications and an excellent choice for developers looking to add OCR to their web applications.

Previous Next

Getting Started with Tesseract.js

The recommend way to install Tesseract.js is using npm. Please use the following command for a smooth installation

Install Tesseract.jsvia npm

 npm install tesseract.js

You can also install it manually; download the latest release files directly from GitHub repository.

Convert Image to Text via JavaScript API

The open source JavaScript library Tesseract.js makes it easy for software developers to Work with various types of images such as BMP, JPG, PNG, PBM, WebP and may more. The library supports extracting text from images to automate the processing of texts on images, PDFs, and scanned documents. The following example shows how to load an image and extracted text from it with just a couple of lines of code. The language argument is used to determine the trained language data to be used in processing of images. Software developers can use multiple languages over here.

How to Convert Image to Text using JavaScript API?

Tesseract.recognize(
  image,language,
  { 
    logger: m => console.log(m) 
  }
)
.catch (err => {
  console.error(err);
})
.then(result => {
 console.log(result);
})
}

Read an Image Region & Extract Text via JS API

The open source JavaScript library has included a very useful features for reading a particular area inside an image and capture its data inside JavaScript applications. The API supports capturing the image area and tries to recognize text inside this region using the internal powerful OCR engine. The following examples shows how software developers can provide URL to the image and the API can easily detect and recognize text in the selected area.

Read and Recognize Text in a Selected Region of an Image via JS API

const { createWorker } = require('tesseract.js');

const worker = await createWorker();
const rectangle = { left: 0, top: 0, width: 500, height: 250 };

(async () => {
  await worker.loadLanguage('eng');
  await worker.initialize('eng');
  const { data: { text } } = await worker.recognize('https://tesseract.projectnaptha.com/img/eng_bw.png', { rectangle });
  console.log(text);
  await worker.terminate();
})();
 English