# PDF Table Extractor: PDF to JSON and Excel (`athletic_chill/pdf-tables-totals-check`) Actor

Returns tables from PDF URLs as typed JSON rows, with an optional Excel file. When a table has a printed total row, each column's sum is checked against it. For invoice tables and reports. Text-based PDFs only.

- **URL**: https://apify.com/athletic_chill/pdf-tables-totals-check.md
- **Developed by:** [Serhii Shevchenko](https://apify.com/athletic_chill) (community)
- **Security:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 pdf page with a tables

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: PDF to JSON and Excel

Extract tables from PDF files and get them back as clean JSON or an Excel file. Give it PDF URLs, and it returns every table as typed rows. When a table has a printed total row, it also adds up each numeric column and compares the sum with that total, so a mismatch gets flagged.

Useful for pulling invoice tables, price lists, reports and statements out of PDFs, for bookkeepers checking supplier invoices, and for AI agents that need numbers from a document instead of a wall of text.

**This Actor reads text-based PDFs only.** It doesn't do OCR, so scanned PDFs and photos of documents return no tables. Those pages are reported and not charged.

### What you get

One dataset record per table:

| Field | Meaning |
|---|---|
| `recordType` | `table`, or `issue` for something that was not read or not charged |
| `sourceUrl` | The PDF the table came from |
| `page`, `pages` | First page of the table, and all its pages if it runs over several |
| `columns` | Each column's name and type: `number`, `date`, `text` or `empty` |
| `rows` | Data rows in column order. Numbers are numbers, and dates are ISO dates |
| `totalRow` | The printed total row, kept apart from the data rows |
| `totalsStatus` | `CHECK` if a column disagrees, `OK` if the printed totals match, `NO_PRINTED_TOTAL` if nothing could be compared |
| `totalsCheck` | Per column: `status`, `computedSum`, `printedTotal`, `difference`, `unparsedCells` |
| `detection` | `ruled` for tables with lines, `text_alignment` for tables worked out from text positions |

The run also saves a `SUMMARY` record with pages read, pages charged and columns flagged. Turn on **Excel file** to get `tables.xlsx`, with a sheet per table and a Checks sheet.

### The totals check

For each numeric column, the Actor adds up the rows and compares the sum with the printed total row. Labels such as Total, Grand total, Subtotal, Sum, Razem, Suma, Summe and Gesamt are recognized.

```json
{
  "column": "Net",
  "status": "CHECK",
  "computedSum": 4821.0,
  "printedTotal": 4812.0,
  "difference": 9.0,
  "unparsedCells": 0
}
```

| Status | Meaning |
|---|---|
| `OK` | The rows add up to the printed total |
| `CHECK` | They don't. Look at this column |
| `NO_PRINTED_TOTAL` | The column has numbers but no printed total, so only the sum is given |
| `TOO_FEW_ROWS` | One number sits above a total, such as Tax above Total, so the two can't be compared |

`CHECK` means the arithmetic doesn't match what the Actor read. It doesn't prove the document is wrong: check the source before acting on it. `unparsedCells` counts filled cells that were left out of the sum.

### Input example

```json
{
  "pdfUrls": ["https://example.com/invoice-1042.pdf"],
  "pages": "1-3",
  "maxPages": 20,
  "includeXlsx": true
}
```

- `pdfUrls`: direct http or https links. Up to 100 per run.
- `pages`: optional, such as `1-3,7`. Applies to every PDF.
- `maxPages`: most pages to read in the whole run, across all PDFs. It also caps the cost of a run.
- `includeXlsx`: also save an Excel file.

The links must be reachable without logging in. Links to private or local addresses aren't accepted.

### Pricing

You pay per page that returns a table, plus Apify's small start fee of $0.00005 per run. These pages are not charged:

- scanned or blank pages
- pages with no table on them
- pages that couldn't be read
- PDFs that failed to download or aren't PDFs

Each of these appears in the results as an `issue` record, with a `reason` and the page numbers. If your spending limit runs out, the Actor stops at that page and reports the pages it didn't read.

### Limits

- Text-based PDFs only. No OCR.
- 20 MB per PDF, 60 seconds per download, and 2 minutes of processing per PDF.
- Password-protected PDFs aren't supported.

### What works well, and what doesn't

Tables with ruled lines work best, including tables that run over many pages. Borderless tables are worked out from text positions, which is less reliable, so those records say `text_alignment`.

Known weak spots:

- **Invoices:** many invoices have no total row directly under their line items, so the check has nothing to compare. In our tests, 2 of 11 real invoices compared cleanly. The rest still returned their tables, with no totals verdict.
- **Headers:** a header that spans several rows or merged cells can come back partly joined, or as `Column 1`, `Column 2`.
- **Close columns:** two columns with a narrow gap can end up in one text cell, such as `€ 399,00 21%`.
- **Financial statements:** running subtotals like "Total current assets" aren't treated as printed totals, so those columns aren't checked.
- **Layout boxes:** labels and amounts inside the same box, common in hotel and utility bills, can come back as text.
- **Number formats:** `1.234` is read as 1.234, not 1234, unless the text shows otherwise. If that's wrong, the column shows `CHECK`, not a false `OK`.
- **Charts and forms:** text inside line charts is ignored, but bar charts and other figures can still produce a table of stray labels.

Documents are processed in memory and aren't written to logs. The extracted tables are saved to your run's dataset, as with any Actor.

Built with Claude, an AI, and tested with real PDFs.

# Actor input Schema

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

Required. An array of URL strings, such as \["https://example.com/invoice.pdf"]. Each must be a direct http or https link that returns a text-based PDF without a login. Up to 100 URLs per run and 20 MB per file.

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

Optional. A string of page numbers and ranges to read in every PDF, such as "1-3,7". Omit it to read from page 1.

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

Optional. A whole number from 1 to 500, default 20. The most pages to read across all PDFs in the run, in order. Pages past it are not read and are listed in an issue record. Only pages that return a table are charged, so this also caps the cost.

## `includeXlsx` (type: `boolean`):

Optional. true or false, default false. When true, also saves all tables and a Checks sheet as tables.xlsx in the run's key-value store.

## Actor input object example

```json
{
  "pdfUrls": [
    "https://raw.githubusercontent.com/jsvine/pdfplumber/stable/examples/pdfs/background-checks.pdf"
  ],
  "maxPages": 20,
  "includeXlsx": false
}
```

# Actor output Schema

## `tables` (type: `string`):

Rows, column types and the totals check for each table.

## `summary` (type: `string`):

Pages read, pages charged, and columns flagged.

## `workbook` (type: `string`):

All tables and a Checks sheet. Exists only if Excel file was turned on.

# 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://raw.githubusercontent.com/jsvine/pdfplumber/stable/examples/pdfs/background-checks.pdf"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("athletic_chill/pdf-tables-totals-check").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://raw.githubusercontent.com/jsvine/pdfplumber/stable/examples/pdfs/background-checks.pdf"] }

# Run the Actor and wait for it to finish
run = client.actor("athletic_chill/pdf-tables-totals-check").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://raw.githubusercontent.com/jsvine/pdfplumber/stable/examples/pdfs/background-checks.pdf"
  ]
}' |
apify call athletic_chill/pdf-tables-totals-check --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,athletic_chill/pdf-tables-totals-check"
        }
    }
}
```

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/NiUrVGaZQe9BDm7ru/builds/I8xdgaUlHpQIzjg4k/openapi.json
