# Extract tables from PDFs (scanned & Arabic) to JSON (`fifty50labs/pdf-table-extractor-arabic-ocr`) Actor

Returns every table in a PDF as JSON rows and cells, plus per-page Markdown and text. Works on scanned (image) PDFs with Arabic + English OCR and on digital PDFs, with correct right-to-left order. Use for invoices, bank statements, government gazettes, price lists. Not for images or Word files.

- **URL**: https://apify.com/fifty50labs/pdf-table-extractor-arabic-ocr.md
- **Developed by:** [Fifty50 Labs](https://apify.com/fifty50labs) (community)
- **Categories:** AI, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$15.00 / 1,000 page extracteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## PDF Table Extractor: scanned & Arabic PDFs to JSON

Turn **every table in a PDF into JSON rows and cells**, with per-page Markdown and text. It works on **scanned (image-only) PDFs** using Arabic + English OCR, and on normal digital PDFs. Arabic tables come back in **correct right-to-left order**, with no reversed words and no flattened columns.

**Use it for:** invoices, bank statements, price lists, tariff schedules, government gazettes, tenders, financial statements, and any Arabic, English or French PDF where you need the table and not just the text.
**Not for:** images (JPG/PNG), Word or Excel files, handwriting, or charts.

**Price: $15 per 1,000 pages read** ($0.015 a page). Every table on the page is included. Failed downloads and failed pages are free.

### Why this exists

Most PDF tools and LLM file readers flatten tables into one stream of text. Merged cells break, columns slide, and Arabic often comes out **backwards** (for example, ةعبطلا instead of الطبعة). Scanned PDFs have no text at all, so the model guesses. This Actor:

- finds table grids on scanned pages from their ruling lines, then reads each cell with **Tesseract OCR (ara+eng)**;
- reads digital PDFs from their **text layer** and rebuilds each cell's text from glyph positions, which fixes visually stored (reversed) Arabic and keeps the numbers in the right order;
- returns columns in **reading order** (rightmost column first for Arabic tables) with a `direction` flag;
- converts Arabic-Indic digits (٠١٢٣) to 0-9 so numbers parse (you can turn this off);
- straightens skewed scans, removes dot leaders (.......), and reads Latin digits with the English model so amounts like `1,89` and `104,5` come out right;
- **flags low-confidence OCR** (`low_ocr_confidence`) instead of guessing.

### Input

| Field | Default | What it does |
|---|---|---|
| `pdfUrls` | (required) | Public links to PDFs, up to 60 MB each |
| `pages` | all | 1-based pages, e.g. `1-3,7`. Set this to pay only for the pages you need |
| `maxPagesPerPdf` | 20 | Safety cap per PDF |
| `ocrMode` | `auto` | `auto` (OCR only for scanned pages), `always`, or `never` |
| `ocrLanguages` | `ara+eng` | Also `ara`, `eng`, `fra`, `ara+eng+fra`, `eng+fra` |
| `normalizeDigits` | `true` | Converts Arabic-Indic digits to 0-9 |
| `includePageText` | `true` | Adds each page's plain text |

Example (one scanned Arabic page, which finishes in about 15 s):

```json
{ "pdfUrls": ["https://www.joradp.dz/FTP/jo-arabe/1990/A1990001.pdf"], "pages": "20" }
```

### Output

You get one dataset item per page:

```json
{
  "pdfUrl": "https://…/A1990001.pdf",
  "status": "ok",
  "page": 29,
  "method": "ocr",
  "direction": "rtl",
  "tableCount": 3,
  "tables": [
    {
      "direction": "rtl",
      "nRows": 6, "nCols": 2,
      "header": ["التعيين", "التعريفة"],
      "rows": [["شغل نفق بوصل مجاري", "1,89 دج عن المتر الخطي سنويا"], ["خط جوي", "0,47 دج عن المتر الخطي سنويا"]],
      "cells": [["التعيين", "التعريفة"], ["…", "…"]],
      "method": "ocr",
      "ocrConfidence": 84.0,
      "flags": [],
      "bbox": [43.6, 107.3, 687.0, 368.3]
    }
  ],
  "markdown": "… | التعيين | التعريفة | …",
  "text": "…",
  "ocrConfidence": 81.7,
  "warnings": []
}
```

- `cells[0]` is the header row and `rows` holds the body. Columns follow reading order.
- `flags` can include `low_ocr_confidence` or `single_column_check_layout`.
- `method` tells you whether the values came from the text layer (exact) or from OCR (check them when `ocrConfidence` is under about 70).

### Use from AI agents (MCP)

The Actor runs with limited permissions, so it works through the **Apify MCP server** (`call-actor`). For agent calls:

1. Pass `pdfUrls` and a small `pages` range. One to three scanned pages finish inside the 30-second MCP wait.
2. Read `tables[].cells` straight from the dataset; there is no need to parse Markdown.
3. Set `maxTotalChargeUsd` on the run to cap spend. The run stops cleanly when the cap is reached.

### Accuracy, honestly

- **Digital PDFs:** exact text, including Arabic and mixed Arabic/Latin numbers.
- **Scanned PDFs:** results depend on scan quality. On our fixed test set (a 1990 Algerian Official Journal scan with 7 Arabic tariff tables), 85% of the expected rows came back with every value correct before release. Bordered tables work best. Borderless scanned tables come back as page text, not cells.
- Handwriting and stamps are not read.

### Privacy

Files are downloaded into the run, processed in memory, and not stored anywhere except your run's own dataset, which follows your Apify data-retention setting. Nothing is sent to third-party AI services.

### Keywords

pdf table extractor, scanned pdf to json, arabic pdf ocr, arabic table extraction, extract tables from pdf, pdf to markdown tables, RTL pdf, invoice table extraction, bank statement pdf to json, government pdf arabic, OCR arabic tables, MCP pdf tool, استخراج جداول من PDF, تحويل PDF عربي إلى Excel

# Actor input Schema

## `pdfUrls` (type: `array`):

Public http(s) links to PDF files, one per line. Scanned (image-only) and digital PDFs both work. Max 60 MB per file. Example: https://www.joradp.dz/FTP/jo-arabe/1990/A1990001.pdf

## `pages` (type: `string`):

Which pages to read, 1-based: e.g. "1-3,7" or "20". Leave empty for all pages (still capped by maxPagesPerPdf). You pay per page read, so set this to cut cost.

## `maxPagesPerPdf` (type: `integer`):

Safety cap on pages read from each PDF. Default 20.

## `ocrMode` (type: `string`):

auto = OCR only pages with no text layer (scans); always = OCR every page (use when the text layer is garbled); never = text layer only (fastest).

## `ocrLanguages` (type: `string`):

Tesseract language models for scanned pages. ara+eng suits Gulf and Arab-world documents with Latin digits.

## `normalizeDigits` (type: `boolean`):

Turn ٠١٢٣٤٥٦٧٨٩ and ۰۱۲۳۴۵۶۷۸۹ into 0123456789 so numbers parse. On by default.

## `includePageText` (type: `boolean`):

Add the page's plain text (text outside tables included) to each item. Markdown with tables is always included.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://www.joradp.dz/FTP/jo-arabe/1990/A1990001.pdf"
  ],
  "pages": "20",
  "maxPagesPerPdf": 20,
  "ocrMode": "auto",
  "ocrLanguages": "ara+eng",
  "normalizeDigits": true,
  "includePageText": true
}
```

# Actor output Schema

## `pages` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "pdfUrls": [
        "https://www.joradp.dz/FTP/jo-arabe/1990/A1990001.pdf"
    ],
    "pages": "20"
};

// Run the Actor and wait for it to finish
const run = await client.actor("fifty50labs/pdf-table-extractor-arabic-ocr").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "pdfUrls": ["https://www.joradp.dz/FTP/jo-arabe/1990/A1990001.pdf"],
    "pages": "20",
}

# Run the Actor and wait for it to finish
run = client.actor("fifty50labs/pdf-table-extractor-arabic-ocr").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "pdfUrls": [
    "https://www.joradp.dz/FTP/jo-arabe/1990/A1990001.pdf"
  ],
  "pages": "20"
}' |
apify call fifty50labs/pdf-table-extractor-arabic-ocr --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,fifty50labs/pdf-table-extractor-arabic-ocr"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/ZeL2Qpqdwmc0ZuCwy/builds/w2mlo6XUIOflairsO/openapi.json
