# PDF Table & Bank-Statement Extractor (`automation_curious/pdf-table-bank-statement-extractor`) Actor

Extract tables & bank-statement transactions from PDFs into clean JSON, CSV, or XLSX-ready rows. Bank-statement mode with confidence scoring works even on line-less PDFs. No OCR: scanned pages are flagged, never guessed. Page selection supported.

- **URL**: https://apify.com/automation\_curious/pdf-table-bank-statement-extractor.md
- **Developed by:** [Sparkfund HQ](https://apify.com/automation_curious) (community)
- **Categories:** Automation, Agents
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$30.00 / 1,000 page parseds

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## PDF Table & Bank-Statement Extractor

Extract tables and bank-statement transactions from PDF files into clean,
structured rows (JSON dataset, per-table CSV, or XLSX-ready row objects).

Text-layer first, honest fallbacks: this actor reads the embedded text of
the PDF with [pdfplumber](https://github.com/jsvine/pdfplumber). It does **not**
run OCR — scanned-image pages are reported as skipped with a clear warning
rather than silently returning garbage.

### What it does

- **Generic table extraction** — ruled-line tables via pdfplumber's default
  strategies; for line-less layouts (common in bank statements) it falls back
  to word-position clustering.
- **Bank-statement heuristic mode** — detects `Date / Description / Debit /
  Credit / Balance` style layouts, anchors columns on the header row, routes
  amounts to debit/credit/balance columns and text to description, and tags
  results with a confidence score (0–1).
- **Multiple input methods** — public PDF URLs (`pdfUrls`) or a base64-encoded
  upload / key-value-store key (`pdfBase64`).
- **Page selection** — e.g. `"1,3-5"`. Only parsed pages count toward billing.

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `pdfUrls` | list of URLs | — | Publicly downloadable PDFs. |
| `pdfBase64` | string | — | Base64 PDF (or KVS key). Takes precedence over URLs. |
| `mode` | `auto` / `tables` / `bank-statement` | `auto` | Detection mode. |
| `pages` | string | all | 1-based page range like `1,3-5`. |
| `outputFormat` | `json` / `csv` / `xlsx-rows` | `json` | `csv` writes one CSV per table to the key-value store. |
| `includePageText` | boolean | `false` | Adds raw page text items for audit/debug. |
| `minTableColumns` | integer | `2` | Discard narrower tables. |

### Output

Dataset items:

```json
{
  "source": "statement.pdf",
  "page": 1,
  "kind": "bank_statement",
  "tableIndex": 0,
  "columns": ["Date", "Description", "Debit", "Credit", "Balance"],
  "rows": [{"Date": "01/03/2026", "Description": "OPENING BALANCE",
            "Debit": "", "Credit": "", "Balance": "2,450.00"}],
  "rowCount": 9,
  "confidence": 0.986
}
```

`kind` is one of `bank_statement`, `table`, `no-table`, `skipped`
(scanned/no text layer), `error`, or `page_text`. Warnings are attached
per item when something is off (forced-mode low confidence, header-only
tables, missing text layer, etc.).

### Example run (local)

```bash
python -m venv .venv && source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -r requirements.txt
python tests/make_fixture.py                        # synthetic 'Test Bank N/A' statement
cp INPUT.json storage/key_value_stores/default/INPUT.json
APIFY_LOCAL_STORAGE_DIR=storage python -m src.main  # or: apify run
```

### Limitations (honest list)

- No OCR. Scanned PDFs return `kind: "skipped"` items.
- Line-less extraction relies on layout geometry; heavily multi-column
  statements may need `mode: "bank-statement"` or produce lower-confidence
  output. Always sanity-check `confidence`.
- Amounts are returned as strings exactly as printed (`$`, commas,
  parentheses for negatives preserved).
- Multi-page statements are extracted per page; running balances that
  continue across pages are not merged.

### Pricing

Pay-per-event metadata is prepared in `.actor/actor.json`
(`PAGE_PARSED` @ $0.03/page) but **disabled** until an Apify developer
account exists; enable it in Apify Console before publishing.

### Status

v0.1.0 — local smoke-tested only. See `QA.md` for what has and has not been
tested on the Apify platform.

# Actor input Schema

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

Publicly downloadable URLs of PDF files to process. Provide URLs here OR upload a PDF as base64 via pdfBase64.

## `pdfBase64` (type: `string`):

Base64-encoded PDF content. Takes precedence over pdfUrls when set.

## `mode` (type: `string`):

auto: detect bank-statement layout per page, else generic tables.

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

Pages to process, 1-based, e.g. '1,3-5'. Empty = all pages.

## `outputFormat` (type: `string`):

Output format of extracted tables.

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

Add raw page text for debugging/audit.

## `minTableColumns` (type: `integer`):

Discard detected tables with fewer columns than this.

## Actor input object example

```json
{
  "pdfUrls": [],
  "mode": "auto",
  "outputFormat": "json",
  "includePageText": false,
  "minTableColumns": 2
}
```

# Actor output Schema

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

No description

## `csvFiles` (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": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("automation_curious/pdf-table-bank-statement-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 = { "pdfUrls": [] }

# Run the Actor and wait for it to finish
run = client.actor("automation_curious/pdf-table-bank-statement-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 '{
  "pdfUrls": []
}' |
apify call automation_curious/pdf-table-bank-statement-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,automation_curious/pdf-table-bank-statement-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/lMeyWdB09HPyfbgzd/builds/dfc6IhN5bB6pXkjXd/openapi.json
