# PDF and Image Table Extractor (CSV, Excel, Markdown) (`enthusiastic_ginkgo_7ie/pdf-image-table-extractor`) Actor

Finds ruled tables in PDFs and scanned images (PNG, JPG, TIFF) and returns one dataset item per table, plus CSV, Excel and Markdown files. Scans are read with built-in OCR in six languages. Source files are never stored; logs hold counts only. Pay per page, only for files that produced a table.

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

## Pricing

from $4.00 / 1,000 processed pages

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 and Image Table Extractor (CSV, Excel, Markdown)

Finds the tables in PDF files and in scanned images (PNG, JPG, TIFF) and returns them as one dataset item per table, one CSV file per table, one Excel workbook with a sheet per table and one Markdown file. Pages with a text layer are read directly; scanned pages and images are read with built-in OCR. The actor detects tables drawn with ruled lines (a grid). It does not detect tables made only of aligned columns of text, does not fill in forms, and does not keep or log the documents it reads.

#### Why use this actor

- **Three output formats from one run.** Every table is a dataset item (`rows` and `markdown`), a CSV file, a sheet in `tables.xlsx` and a section in `tables.md`.
- **Text PDFs and scans in one actor.** PDF pages with a text layer are read exactly, with no OCR and no OCR charge. Scanned pages and image files go through Tesseract OCR in English, German, French, Spanish, Italian or Portuguese.
- **Documents are not kept.** Files are downloaded into memory, read there and dropped. Nothing about a document is logged beyond counts and page numbers (see Privacy).
- **No charge for files without tables.** Both events are charged only for files that produced at least one table. A run where no file yields a table ends as failed, with the reason, and no page is charged.
- **Bounded runs.** Maximum pages per run (up to 200) and maximum file size (up to 50 MB) are inputs, and the run's maximum cost is respected before every file.

#### Input

| Field | Type | Description |
|---|---|---|
| `sources` | list of text | Links to PDF, PNG, JPG or TIFF files, up to 50. The file type is read from the file itself. The prefill is two synthetic samples: a PDF with text tables and a PNG scan. |
| `ocrMode` | `auto`, `always`, `off` | `auto` (default) reads PDF pages without a text layer, and all images, with OCR. `always` runs OCR on every PDF page, even pages with text. `off` never runs OCR: images are skipped and scanned pages give no tables. |
| `ocrLanguage` | `eng`, `deu`, `fra`, `spa`, `ita`, `por` | Language of the text in scans. One language per run. Default `eng`. |
| `maxPages` | integer | Pages processed in one run, counted over all files in order, 1 to 200. Default 200. Pages beyond the limit are not processed and not charged. |
| `maxFileMb` | integer | Largest file accepted, 1 to 50 MB. Default 50. Larger files are skipped and named in the summary. |

#### Output

Each dataset item is one table:

| Field | Description |
|---|---|
| `sourceName` | File name of the document, without the query string of its link. |
| `page`, `tableIndex` | Page number (from 1) and the table's number on that page (from 1, top to bottom). |
| `method` | `text` for a table read from a PDF text layer, `ocr` for a table read from a picture. |
| `nRows`, `nCols` | Size of the table. A table has at least 2 rows and 2 columns. |
| `rows` | The cells as a list of rows, each a list of text. Empty rows and empty columns are dropped, line breaks inside a cell become spaces. |
| `markdown` | The same table as a Markdown pipe table. The first row is the header. |

The key-value store of the run holds the same tables as files:

| Key | Content |
|---|---|
| `table-p<page>-<n>.csv` | One CSV file (UTF-8) per table. With several files in a run the key is `table-s<file number>-p<page>-<n>.csv`. |
| `tables.xlsx` | One Excel workbook, one sheet per table (`p1-t1`, or `s2-p1-t1` with several files). Every cell is text exactly as read: nothing is turned into a number or a date and formulas are never evaluated. |
| `tables.md` | Every table as Markdown under a heading with its file name, page and table number. |
| `SUMMARY` | Counts per file (pages, pages processed, OCR pages, tables, failed pages, skipped files and why) and for the run (pages and OCR pages actually charged, whether OCR scratch files were kept in `/dev/shm`). It holds no table content. |

#### Privacy

- **In memory.** Each file is downloaded into memory and processed there. A source document is never written to the key-value store, the dataset or any other storage. Pictures of pages exist only as the OCR scratch files described next.
- **OCR scratch files stay in RAM.** Tesseract needs a picture file per page. It is written to a temporary folder under `/dev/shm` (memory-backed on Linux) and deleted right after the page. If `/dev/shm` is not available the default temporary folder is used, this is logged once, and the `SUMMARY` flag `ocrTempInShm` is `false`.
- **Logs hold counts and page numbers only.** No cell text, recognised text, file name or link is written to the log or to a status message, and error messages from the document libraries are never quoted. File names appear only in the `SUMMARY` record.
- **What is stored.** The extracted tables are the result, so they are in the run's dataset and key-value store, like the output of any actor. The links in `sources` are part of the run input that Apify stores. Use short-lived signed links for sensitive documents and delete the run when the tables are no longer needed.
- **No outside services.** OCR runs inside the container with Tesseract. Documents are fetched from the links given and sent nowhere else.

#### Pricing

This actor uses pay-per-event pricing. Both events are charged only for a file that produced at least one table, and only after its tables are delivered.

| Event | Price | Charged when |
|---|---|---|
| `page-processed` | $0.004 | Once per page read in a file that produced at least one table. Pages of that file without a table count too. |
| `ocr-page` | $0.012 | In addition, once per page read with OCR (a scanned PDF page or an image) in a file that produced at least one table. |

A page read from a text layer costs $0.004. A page read with OCR costs $0.004 + $0.012 = $0.016.

Worked example: three files in one run.

- A 10-page text PDF with tables on 4 pages: 10 x $0.004 = $0.04 (all 10 pages are charged, because the file produced tables).
- A 3-page scanned PDF with a table on each page: 3 x $0.004 + 3 x $0.012 = $0.048.
- A 5-page PDF with no ruled tables: nothing is charged, the file produced no table.

Total: $0.04 + $0.048 = $0.088. A run in which no file produces a table fails and no page is charged. Pages that fail to read, and pages left out by `maxPages` or by the run's maximum cost, are not processed and not charged. A file that cannot be downloaded or read is skipped and not charged.

Apify's standard `apify-actor-start` event also applies to every run, at $0.00005 per GB of run memory, so $0.0001 at the default 2 GB. It is left out of the example. The run's maximum cost is priced page by page, with an OCR page counted at both of its events ($0.016): a page is read only if the money left in the limit pays for it, so a run never delivers pages it cannot charge. For example, a maximum cost of $0.10 pays for 6 OCR pages ($0.096) or 25 text pages. The limit is read again before every file, and a scan that no longer fits is skipped while a cheaper text page after it can still be read. The status message and the `SUMMARY` fields `pagesCharged` and `ocrPagesCharged` report what was actually charged.

#### FAQ

**Which tables are detected?**
Tables drawn with ruled lines, in PDF text layers and in pictures. Tables that are only aligned columns of text, without ruled lines, are not detected: guessing them also finds "tables" in ordinary paragraphs, and a wrong table would be charged. A file with only such tables produces no table and costs nothing.

**How accurate is the OCR?**
It depends on the scan: resolution, skew, contrast and the language setting all matter. PDF pages are rendered at 300 dpi, and the ruled lines are painted out of the picture before the text is read, because Tesseract cannot read text inside a grid. Check recognised numbers before relying on them; the `method` field tells text-layer tables from OCR tables.

**Why was a file not charged?**
Either it produced no table, or it could not be downloaded or read (not a PDF or image, password-protected, over `maxFileMb`, or corrupt). The `SUMMARY` record names each file with its status and reason.

**A scanned PDF gave no tables with `ocrMode` set to `off`. Why?**
With OCR off only the text layer is read, and a scan has none. The failed run's message says how many pages had no text layer. Use `auto`.

**What about PDFs that were already OCR'd (scans with a hidden text layer)?**
Their ruled lines are part of the picture, not of the PDF, so the text layer alone shows no table. Use `ocrMode` `always` to read every page as a picture.

**How long does a run take?**
Text-layer pages are fast: 60 pages from 30 files took 17 seconds in a test. OCR is slower: 15 scanned pages took 65 seconds at the default 2048 MB of memory, about 4 seconds a page, so a 200-page scan needs roughly 15 minutes. Peak memory was 82 MB for text pages and 347 MB for OCR on Letter-size pages at 300 dpi. Pages larger than 30 megapixels are rendered at a lower resolution. Image files above 50 megapixels are refused; a 50-megapixel photo needs about 1.5 GB of memory before OCR starts, which is why the actor asks for at least 2048 MB.

**What happens with a multi-page TIFF?**
Each frame is one page, counted against `maxPages` and charged like any other page.

**How do pages with several tables behave?**
Every table is its own item, numbered from the top of the page. A page is charged once, whatever the number of tables on it.

#### Disclaimer

This actor is not affiliated with, endorsed by or sponsored by Microsoft Corporation. Excel is a trademark of Microsoft Corporation and is named only to describe the file format. OCR uses the open-source Tesseract engine. Users are responsible for having the right to process the documents they submit and for the lawful use of the extracted data.

#### Report issues

Report problems or request features in the Issues tab of this actor. Please describe the problem without attaching documents that contain personal or confidential data.

# Actor input Schema

## `sources` (type: `array`):

Links to PDF, PNG, JPG or TIFF files. Public links, or links that carry their own access signature. The file type is read from the file itself, not from its name. The prefill is two synthetic samples: a PDF with text tables and a PNG scan.

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

Auto reads PDF pages that have no text layer, and all images, with OCR. Always runs OCR on every PDF page, even pages with text (slower and charged as OCR pages). Off never runs OCR: images and scanned pages are skipped.

## `ocrLanguage` (type: `string`):

Language of the text in scanned pages and images. One language per run.

## `maxPages` (type: `integer`):

Upper bound on pages processed in one run, counted over all documents in order. Pages beyond the limit are not processed and not charged.

## `maxFileMb` (type: `integer`):

Files larger than this are skipped with a clear message in the run summary.

## Actor input object example

```json
{
  "sources": [
    "https://api.apify.com/v2/key-value-stores/rKmTb0uCShh9ssnDK/records/u1-sample-text-tables.pdf?signature=ZdQrAcIjOsv0wvPE1CSH",
    "https://api.apify.com/v2/key-value-stores/rKmTb0uCShh9ssnDK/records/u1-sample-scan.png?signature=1hLyzC857TYqj9DuQu4nr"
  ],
  "ocrMode": "auto",
  "ocrLanguage": "eng",
  "maxPages": 200,
  "maxFileMb": 50
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `files` (type: `string`):

No description

## `summary` (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 = {
    "sources": [
        "https://api.apify.com/v2/key-value-stores/rKmTb0uCShh9ssnDK/records/u1-sample-text-tables.pdf?signature=ZdQrAcIjOsv0wvPE1CSH",
        "https://api.apify.com/v2/key-value-stores/rKmTb0uCShh9ssnDK/records/u1-sample-scan.png?signature=1hLyzC857TYqj9DuQu4nr"
    ],
    "ocrMode": "auto",
    "ocrLanguage": "eng",
    "maxPages": 200,
    "maxFileMb": 50
};

// Run the Actor and wait for it to finish
const run = await client.actor("enthusiastic_ginkgo_7ie/pdf-image-table-extractor").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 = {
    "sources": [
        "https://api.apify.com/v2/key-value-stores/rKmTb0uCShh9ssnDK/records/u1-sample-text-tables.pdf?signature=ZdQrAcIjOsv0wvPE1CSH",
        "https://api.apify.com/v2/key-value-stores/rKmTb0uCShh9ssnDK/records/u1-sample-scan.png?signature=1hLyzC857TYqj9DuQu4nr",
    ],
    "ocrMode": "auto",
    "ocrLanguage": "eng",
    "maxPages": 200,
    "maxFileMb": 50,
}

# Run the Actor and wait for it to finish
run = client.actor("enthusiastic_ginkgo_7ie/pdf-image-table-extractor").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 '{
  "sources": [
    "https://api.apify.com/v2/key-value-stores/rKmTb0uCShh9ssnDK/records/u1-sample-text-tables.pdf?signature=ZdQrAcIjOsv0wvPE1CSH",
    "https://api.apify.com/v2/key-value-stores/rKmTb0uCShh9ssnDK/records/u1-sample-scan.png?signature=1hLyzC857TYqj9DuQu4nr"
  ],
  "ocrMode": "auto",
  "ocrLanguage": "eng",
  "maxPages": 200,
  "maxFileMb": 50
}' |
apify call enthusiastic_ginkgo_7ie/pdf-image-table-extractor --silent --output-dataset

```

## MCP server setup

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

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/h7iqLtOpX1IEm4yz8/builds/a3NTKuMQLJz2mjqXl/openapi.json
