How to extract Tables in images / PDF with JavaScript in 5 minutes?
Tags: ai, api, javascript, dataparsing
Published: 2023-04-28 15:35:41

*In this tutorial, you will learn how to use OCR Table API in 5 minutes using JavaScript. Eden AI provides an easy and developer-friendly API that allows you to extract tables in your files.*

‍

## **What is [OCR Table](http://www.edenai.co/feature/ocr-table?referral=how-to-extract-tables-javascript)?**

OCR Table or *Table Parser* refers to the process of using Optical Character Recognition (OCR) technology to extract data from tables within documents, such as scanned PDFs, images, and other types of files.


![OCR Table API result on Eden AI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/di6mgrd23b3fipqigxod.png)


‍

Since tables may contain a lot of structured data, extracting data from tables using general OCR can be challenging because tables often have a complex layout with rows and columns, and the data can be in different formats, such as numbers, text, or dates. Therefore, Table OCR lets you extract tabular data from PDFs and images in one shot by using advanced Image Processing and Machine Learning algorithms to automatically identify and extract the tabular data from the documents.

Other document types like [receipts](https://www.edenai.co/feature/ocr-receipt?referral=how-to-extract-tables-javascript), [invoices](https://www.edenai.co/feature/ocr-invoice?referral=how-to-extract-tables-javascript), [resumes](https://www.edenai.co/feature/ocr-resume?referral=how-to-extract-tables-javascript), [IDs](http://www.edenai.co/feature/ocr-id-passport?referral=how-to-extract-tables-javascript), etc., also follow the same layout and benefit from Table OCR's capabilities.

‍

## **Get Started with OCR and Table Extraction API using JavaScript**

The first step to getting started is to set Axios, a promise-based HTTP client for the browser and Node.js, that will allow you to call Eden AI API.

![https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/638f08881993bd518d9ca0cc_carbon(3).png](https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/638f08881993bd518d9ca0cc_carbon(3).png)

‍

Next, you'll need to initialize the File System module in order to access local files on your computer.

![https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/638f088e8cc139623cbbce22_carbon(2).png](https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/638f088e8cc139623cbbce22_carbon(2).png)

‍

Finally, you'll need to create your multipart/formdata parameters form:

![https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/638f09b0a3de914651c26a15_formdata.png](https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/638f09b0a3de914651c26a15_formdata.png)

‍

## **How to extract table in a PDF or an image with JavaScript**

You are now ready to process your file into Eden AI OCR Table API. You can process files in .pdf, .jpg, .png or .jpeg and [documents in many languages](https://app.edenai.run/user/register?referral=how-to-extract-tables-javascript).

‍

### **1. Get an OCR Table API Key on Eden AI**

To perform OCR Table, you'll need to create an account on [Eden AI](https://app.edenai.run/user/register?referral=how-to-extract-tables-javascript) for free. Then, you will be able to get your **API key** directly from the homepage with free credits offered by Eden AI.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/26oht6vrdr786aqg9hxi.png)

**[Get your API key for FREE](https://app.edenai.run/user/register?referral=how-to-extract-tables-javascript)**


### **2. Let’s Extract Tables with OCR**

Now that you have initialized the required JavaScript modules and got your API key, you will be able to extract text in your file. With Eden AI, you can choose from a wide range of engines you want for OCR Table. You can access the list of OCR Table providers available on Eden AI directly on our documentation [here](https://docs.edenai.co/reference/ocr_ocr_tables_async_create?referral=how-to-extract-tables-javascript).

‍

Here is the JavaScript code to add the form data parameters values for your request:

![https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/6393172d7f45b1603f746afb_carbon(21).png](https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/6393172d7f45b1603f746afb_carbon(21).png)

‍

For example, we called two different OCR Table engines. Once the parameters values are passed, you can configure your request:

![https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/639317610aa62084429443ff_carbon(22).png](https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/639317610aa62084429443ff_carbon(22).png)

‍

Then, you need to create launchJob() function that will execute POST request:

![https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/639317be6d8df4260a9af1b0_carbon(23).png](https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/639317be6d8df4260a9af1b0_carbon(23).png)

‍

Finally, you have to create the getJob() function that will execute GET request with the Job ID of your POST request:

![https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/6393198e6d8df40aea9b0ec8_carbon(24).png](https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/6393198e6d8df40aea9b0ec8_carbon(24).png)

‍

You will first get this response:

![https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/63468b71bcd332585a894d57_table-get-process.png](https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/63468b71bcd332585a894d57_table-get-process.png)

‍

Once the request is done (status : finished), you will be able to get the result for OCR Table task:

![https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/63468caaeabc8879eaaa2875_table-get-response.png](https://uploads-ssl.webflow.com/61e7d259b7746e3f63f0b6be/63468caaeabc8879eaaa2875_table-get-response.png)

‍

## **Benefits of using OCR Table API with Eden AI**

Using Table Extraction with Eden AI API is quick and easy.


![Multiple AIs in one API - Eden AI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2pa9ngqobpkfs9jss91l.gif)


### **Save time and cost**

We offer a unified API for all providers: simple and standard to use, with a quick switch between providers and an access to the specific features of each provider.

‍

### **Easy to integrate**

The JSON output format is the same for all suppliers thanks to Eden AI's standardisation work. The response elements are also standardised thanks to Eden AI's powerful matching algorithms.

‍

### **Customization**

With Eden AI you have the possibility to integrate a third party platform: we can quickly develop connectors. To go further and customize your OCR Table request with specific parameters, check out our [documentation.](https://docs.edenai.co/reference/ocr_ocr_tables_async_create?referral=how-to-extract-tables-javascript)

**[Create your Account on Eden AI](https://app.edenai.run/user/register?referral=how-to-extract-tables-javascript)**