# My Actor (`chestnut_sweetgum_hsj/pdf-table-extractor`) Actor

Extract tables from PDFs into structured CSV/JSON using pdfplumber (MIT). Batch many PDF URLs, isolate per-file errors, and charge only for PDFs that actually yield tables. Built for data pipelines, RAG ingestion and spreadsheet QA.

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

## Pricing

$30.00 / 1,000 pdf table extractions

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 — turn PDF tables into structured CSV / JSON

Pull the tables out of PDF reports, invoices, financial statements and papers and
get them back as **structured, analysis-ready data** — one clean record per PDF.

Point this Actor at a list of PDF URLs and it returns, for each file, the full
set of extracted tables as CSV text and/or a structured JSON array. Built for
data pipelines, spreadsheet QA, and RAG ingestion where you need the *numbers*,
not the page layout.

No format juggling. No copy-paste. No half-parsed grids. One call, structured
output.

***

### Why this exists

Every data team hits the same wall: the numbers live inside a 40-page PDF
earnings report or a scanned invoice, and the only way to get them into a
spreadsheet is manual copy-paste. PDF byte streams are not data — they are
pictures of data.

This Actor does the ingestion step for you, using the same table-extraction
engine behind thousands of data pipelines — **pdfplumber** — battle-tested across
millions of PDFs.

**Typical jobs it saves you from:**

- Pulling quarterly figures out of a pile of PDF earnings reports
- Turning invoice tables into CSV for accounting reconciliation
- Converting research-paper result tables into JSON for analysis
- Building a structured table feed for a RAG / vector search pipeline

***

### What you get

One dataset record per input PDF:

```json
{
  "source": "https://example.com/reports/q3-earnings.pdf",
  "outputFormat": "both",
  "numTables": 2,
  "csv": "# page 1 table 1\nSegment,Revenue (B),YoY\nCloud,4.2,+18%\n...",
  "tables": [
    { "page": 1, "index": 1, "rows": [["Segment","Revenue (B)","YoY"],["Cloud","4.2","+18%"]] }
  ],
  "status": "ok",
  "error": null
}
```

Failed or table-less PDFs never kill the batch — they come back with
`status: "empty"` / `"failed"` and a human-readable `error` message, while every
other PDF still extracts. **You are only charged for PDFs that actually yield
tables.**

***

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `pdfUrls` | array of strings | `[]` | Direct HTTP/HTTPS links to PDF files (reports, invoices, papers). |
| `outputFormat` | `csv` | `json` | `both` | `both` | `csv` = one concatenated CSV; `json` = structured table array; `both` = both. |
| `password` | string | `""` | Open password for encrypted PDFs. Leave blank for unprotected files. |

At least one `pdfUrls` entry must be provided.

#### Example input

```json
{
  "pdfUrls": [
    "https://example.com/reports/q3-earnings.pdf",
    "https://example.com/invoices/inv-1024.pdf"
  ],
  "outputFormat": "both"
}
```

***

### Output fields

- **`source`** — the PDF URL you submitted, echoed back so you can join results.
- **`outputFormat`** — the requested output format.
- **`numTables`** — how many tables were extracted from this PDF.
- **`csv`** — concatenated CSV text of every table (empty when format is `json`).
- **`tables`** — structured array; each item has `page`, `index` and `rows`
  (a list of cell strings). This is the canonical, machine-readable form.
- **`status`** — `ok` (billed), `empty` (no tables) or `failed` (never billed).
- **`error`** — `null` on success; a short diagnostic message otherwise.

***

### Supported inputs

| Category | Notes |
|---|---|
| Text-based PDF | Native support — tables extracted from the embedded text layer. |
| Encrypted PDF | Provide `password`; extracted after unlocking. |
| Multi-page / multi-table | Every table on every page is captured with its page & index. |
| Scanned / image-only PDF | **Not supported** — pdfplumber reads the text layer only; use an OCR-backed tool (Docling / PaddleOCR) instead. |

***

### Pricing

**Pay per successful PDF — $0.03 per PDF that yields at least one table.**

- PDFs with no tables (`empty`) and failed PDFs (`failed`) are **never** charged.
- You can cap spend per run in the Apify Console.
- No subscription, no minimum, no per-minute compute charge on top.

A 100-PDF extraction job with tables in ~70 of them costs about **$2.10**.

***

### How to use it from code

Using the Apify API:

```bash
curl -X POST "https://api.apify.com/v2/acts/YOUR_USERNAME~pdf-table-extractor/runs?token=YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"pdfUrls":["https://example.com/report.pdf"],"outputFormat":"both"}'
```

Then read the dataset:

```bash
curl "https://api.apify.com/v2/datasets/DATASET_ID/items?token=YOUR_TOKEN&format=json"
```

Or from the Apify Python client:

```python
from apify_client import ApifyClient

client = ApifyClient("YOUR_TOKEN")
run = client.actor("YOUR_USERNAME~pdf-table-extractor").call(
    run_input={"pdfUrls": ["https://example.com/report.pdf"], "outputFormat": "both"}
)
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item["source"], item["numTables"])
```

***

### Common workflows

**Financial ingestion.** Drop a list of earnings-PDF URLs into `pdfUrls`, run once,
pipe the `tables` field straight into your spreadsheet or database.

**Invoice reconciliation.** Convert a folder of invoice PDFs into CSV, diff against
your ledger to catch mismatches.

**Research mining.** Turn a stack of paper result tables into JSON, then load them
into any analysis notebook without manual entry.

**RAG table feed.** Extract tables as structured JSON and chunk them into your
vector store with full page/index traceability.

***

### Limitations (read before you rely on it)

- **Image-only / scanned PDFs are not supported** — pdfplumber reads the text
  layer, not pixels. For scans, use an OCR-backed extractor.
- **Very complex tables** (deeply nested, heavily merged cells, rotated text) may
  need light post-processing; the `page`/`index` of every table is preserved so
  you can target fixes.
- **Paywalled or login-gated PDFs will fail** — this Actor fetches publicly
  accessible URLs only.
- **Encrypted PDFs need `password`** — otherwise they are reported as `failed`.

***

### Built on open source

This Actor is a derivative work of **pdfplumber** (MIT License).

- Upstream: https://github.com/jsvine/pdfplumber
- Original author: Jeremy Singer-Vine
- License: MIT — full text included in `LICENSE`

Attribution is retained as required by the MIT License. The value added here is
the packaging: batch URL input, per-file error isolation, structured dataset
output, CSV/JSON dual format and pay-per-success billing.

# Actor input Schema

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

Direct HTTP/HTTPS links to PDF files (reports, invoices, papers) to extract tables from.

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

csv = one concatenated CSV; json = structured table array; both = csv + json in each record.

## `password` (type: `string`):

Open password for encrypted PDFs. Leave blank for unprotected files.

## Actor input object example

```json
{
  "outputFormat": "both",
  "password": ""
}
```

# Actor output Schema

## `dataset` (type: `string`):

Dataset of extracted tables. Each item contains the source URL, the table data, and a per-source status.

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("chestnut_sweetgum_hsj/pdf-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 = {}

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

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,chestnut_sweetgum_hsj/pdf-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/I27SEo4xlcXEJgJdx/builds/01ntGUfJgbGTuXrdu/openapi.json
