Tutorial

How to Perform Multi-Page OCR Using JavaScript

In this guide, you’ll discover how to perform multi-page OCR using JavaScript and the Eden AI API. We’ll walk through how to initiate an OCR job, fetch the results, and efficiently process large documents using Eden AI’s asynchronous workflow and support for multiple OCR providers.

How to Perform Multi-Page OCR Using JavaScript
TABLE OF CONTENTS

Optical Character Recognition (OCR) is a powerful method for converting text from images or scanned documents into editable, searchable content. With Eden AI’s multi-page OCR feature, handling documents that span several pages becomes simple and efficient.

In this tutorial, you’ll learn how to implement multi-page OCR in JavaScript using the Eden AI API, covering both how to start a job and how to retrieve the results.

What is Multipage OCR?

Multipage OCR (Optical Character Recognition) is a technology that allows users to extract text from documents with multiple pages, such as PDFs or image-based files.

By scanning each page of the document, it recognizes and converts printed text into machine-readable, editable, and searchable formats, making it easier to work with large or scanned documents without manual data entry.

How to use Multipage OCR

Set Up Your Eden AI Account

1. Sign Up: If you don't have an Eden AI account, create a free here. Once you do that you can obtain your API key, which you can use to access Multipage OCR.

2. Access OCR Tools: Once logged in, go to the document parsing section of the platform.

3. Choose the Multipage OCR Feature: Select the Multipage OCR tool. You can also explore advanced parsing options based on your specific requirements

Implementing Multipage OCR using JavaScript

Install JavaScript Requests Module

To interact with APIs in JavaScript, we’ll use Axios, a promise-based HTTP client.


npm install axios

Axios simplifies sending HTTP requests and handling responses, making it perfect for calling RESTful APIs like Eden AI.

Stage 1: Launch the OCR Job (POST Request)

Eden AI uses asynchronous processing for large or complex files (like multi-page PDFs). This means you first launch the job, and then poll the API to retrieve the results once the processing is complete. This two-step flow helps with performance, reliability, and scalability.

This first stage uploads the file to Eden AI and starts the OCR process.


const axios = require('axios');

const API_TOKEN = 'Your_API_Key'; // Replace with your actual API token
const fileUrl = '🔗 URL of your image'; // Replace with the actual URL of the document

const headers = {
  "Authorization": `Bearer ${API_TOKEN}`,
  "Content-Type": "application/json"
};

const jsonPayload = {
  "providers": ["amazon"], // You can also use others like 'google', 'microsoft', etc.
  "file_url": fileUrl
};

axios.post('https://api.edenai.run/v2/ocr/ocr_async', jsonPayload, { headers })
  .then(response => {
    console.log(response.data); // Contains the public_id
  })
  .catch(error => {
    console.error('Error launching OCR job:', error);
  });

Code Explanation:

file_url: URL of your document (can be a multi-page PDF).

providers: Eden AI supports multiple OCR providers (like Amazon Textract).

This call starts the OCR job and returns a public_id used to check job status and retrieve results.

Stage 2: Retrieve the OCR Results (GET Request)

Once the OCR job is complete, use the public_id to fetch the results.


const axios = require('axios');

const publicId = 'your_public_id_here'; // Replace with your actual public_id
const API_TOKEN = 'Your_API_Key'; // Reuse your API token

const headers = {
  "Authorization": `Bearer ${API_TOKEN}`,
  "Accept": "application/json"
};

axios.get(`https://api.edenai.run/v2/ocr/ocr_async/${publicId}/`, { headers })
  .then(response => {
    console.log(response.data); // OCR results here
  })
  .catch(error => {
    console.error('Error retrieving OCR results:', error);
  });

Code Explanation:

  • The GET request checks the job status and retrieves the full OCR output.
  • The result includes all pages and text blocks identified in the document.

Interpreting the Results

Here’s what a typical response might include:


{
  "status": "success",
  "results": {
    "amazon": {
      "text": "Page 1 content...\nPage 2 content...",
      "pages": [
        {
          "page_number": 1,
          "text": "Page 1 content..."
        },
        {
          "page_number": 2,
          "text": "Page 2 content..."
        }
      ]
    }
  }
}

Explanation of Output Fields:

  • status: Shows if the job succeeded.
  • text: Consolidated OCR text from all pages.
  • pages: Contains individual results per page (great for multi-page documents).
  • provider: Indicates which OCR engine produced the result.

Going Further

For better management of your OCR tasks, Eden AI provides additional endpoints. These extra endpoints allow you to track and manage your jobs more effectively. You can:

  1. OCR Async List Job (GET):
    Retrieve a list of all jobs launched for OCR. Use the job IDs to track the status and retrieve the results.
    API Documentation
  2. OCR Async Delete Jobs (DELETE):
    Delete jobs that are no longer needed, keeping your workspace organized and clutter-free.
    API Documentation

These endpoints enhance flexibility and control, helping you manage and clean up OCR tasks efficiently. For further details, refer to the full documentation!

Why Eden AI is the Best Tool for Multipage OCR

Eden AI provides several advantages.

Multiple AI Providers

You can choose between different AI services, helping you compare results for the best performance.

Easy Integration

Simplify development with a single API key that provides access to multiple AI services. Eliminate the hassle of managing separate integrations and accelerate your launch.

Cost Efficiency

Only pay for what you use. No upfront costs, just flexible access to multiple AI services with a single API key.

Conclusion

Leveraging JavaScript with the Eden AI API for multi-page OCR provides an efficient and scalable solution for processing large or complex documents.

By utilizing Eden AI's asynchronous job handling and multiple OCR providers, you can automate text extraction from multi-page documents with ease, saving time and effort while improving accuracy.

Whether for personal use or large-scale applications, this approach ensures smooth document processing every time.

Start Your AI Journey Today

  • Access 100+ AI APIs in a single platform.
  • Compare and deploy AI models effortlessly.
  • Pay-as-you-go with no upfront fees.
Start building FREE

Related Posts

Try Eden AI for free.

You can directly start building now. If you have any questions, feel free to chat with us!

Get startedContact sales
X

Start Your AI Journey Today

Sign up now with free credits to explore 100+ AI APIs.
Get my FREE credits now