# PDF table extraction API: tables as JSON

> Extract tables from PDFs through a PDF to JSON API: each table as rows and cells, numbers as typed values. Free API key, 20 files a day.

Send a PDF with to=json and get each table back as data: its rows and columns, the text of every cell, and numbers as values you can calculate with.

```bash
# API key: switchfile.io/dashboard/keys
code=$(curl -sL "https://api.switchfile.io/v1/convert?wait=30" \
  -o reply -D headers -w "%{http_code}" \
  -H "Authorization: Bearer $SWITCHFILE_API_KEY" \
  -H "Accept: application/octet-stream" \
  -F file=@report.pdf -F to=json)
if grep -qi '^x-incomplete' headers; then
  grep -i '^x-notes' headers  # partial result, left in reply
elif [ "$code" = 200 ] && grep -qi '^content-disposition' headers; then
  mv reply report.json
else
  # 202: still running, fetch links.self. Several files: result.files.
  cat reply  # otherwise the error
fi
```

```js
// npm i switchfile
import Switchfile from "switchfile";

const switchfile = new Switchfile({ apiKey: process.env.SWITCHFILE_API_KEY });
const conversion = await switchfile.convert("report.pdf", "json");
if (conversion.result.incomplete) console.log((conversion.result.notes ?? []).join("\n"));
else await switchfile.download(conversion, "report.json");
```

```python
# pip install switchfile-sdk
import os
import switchfile
switchfile.configure(api_key=os.environ["SWITCHFILE_API_KEY"])
conversion = switchfile.convert("report.pdf", "json")
if conversion["result"]["incomplete"]:
    print("\n".join(conversion["result"].get("notes", [])))
else:
    switchfile.download(conversion, "report.json")
```

```php
<?php // composer require switchfile/switchfile-php
require "vendor/autoload.php";

$switchfile = new Switchfile\Switchfile(["api_key" => getenv("SWITCHFILE_API_KEY")]);
$conversion = $switchfile->convert("report.pdf", "json");
if ($conversion["result"]["incomplete"]) echo implode("\n", $conversion["result"]["notes"] ?? []), PHP_EOL;
else $switchfile->download($conversion, "report.json");
```

[Get a free API key](https://switchfile.io/signup) (Free for 20 files a day, up to 50 pages per conversion.)

## What comes back

With Accept: application/octet-stream, as in the curl example, a 200 response is the file itself when the conversion has exactly one result file. With several result files, for example one image per page, or without that header, you get the conversion as JSON, and the files are in result.files:

```json
{
  "id": "0b8a7c1e-5d0f-4a51-9f39-2f7f4c1d9a10",
  "object": "conversion",
  "status": "finished",
  "progress": 100,
  "input": {
    "filename": "report.pdf",
    "format": "pdf",
    "size": 48213
  },
  "to": "json",
  "options": {},
  "result": {
    "files": [
      {
        "filename": "report.json",
        "size": 61544,
        "url": "https://api.switchfile.io/files/2a6f8e1c-4b3d-4e7a-9c5f-8d1b0e2a4c67/report.json?expires=1794074402&signature=3f9c2a7d41e8b6c05d1f9e2a7b4c8d3e6f0a1b2c3d4e5f60718293a4b5c6d7e8"
      }
    ],
    "incomplete": false
  },
  "download_url": "https://api.switchfile.io/files/2a6f8e1c-4b3d-4e7a-9c5f-8d1b0e2a4c67/report.json?expires=1794074402&signature=3f9c2a7d41e8b6c05d1f9e2a7b4c8d3e6f0a1b2c3d4e5f60718293a4b5c6d7e8",
  "error": null,
  "credits": 1,
  "batch_id": null,
  "created_at": "2026-11-06T18:00:00+00:00",
  "finished_at": "2026-11-06T18:00:02+00:00",
  "expires_at": "2026-11-07T18:00:02+00:00",
  "links": {
    "self": "https://api.switchfile.io/v1/conversions/0b8a7c1e-5d0f-4a51-9f39-2f7f4c1d9a10"
  }
}
```

download_url is a signed link to the result. It works without your API key until expires_at, 24 hours after the conversion finished.

No browser at hand? POST /v1/signup with an email address sends a code, and POST /v1/signup/verify with that code returns the key. [Get an API key without a browser](https://switchfile.io/docs/authentication#get-an-api-key-without-a-browser)

## What you get

- **Rows and cells**: Each table has rows and cols. Each cell has its position, counted from 0, and its text. Merged cells carry rowspan or colspan, and cells never overlap.
- **Numbers as values**: A cell that reads as a number, a percentage, an amount or a date also has a typed value, for example 1234.5 for "1,234.50".
- **Tables over several pages**: A table that runs over several pages stands once, on its first page. Around it, the headings and paragraphs of the page keep their reading order.
- **Scanned pages marked**: Text recognition is on for every PDF. Pages whose text comes from it carry the flag ocr, so your code knows which cells were read from a scan.

Field by field, with an example: [Document JSON in the docs](https://switchfile.io/docs/document-json#tables)

Step by step, with a pandas DataFrame per table: [Extract tables from PDFs in Python](https://switchfile.io/docs/extract-pdf-tables-python)

The documents, every output and the scoring code of our open test of PDF tables are public: [pdf-table-bench on GitHub](https://github.com/switchfile/pdf-table-bench)

Open-source tools and APIs for PDF tables, ranked only by measured values: [PDF table tools ranked by measured values](https://switchfile.io/best-pdf-table-extraction-apis)

Tables for people who work in spreadsheets: [PDF to Excel API](https://switchfile.io/pdf-to-excel-api)

## Options

| Option | Meaning |
|---|---|
| `pages` | Pages to convert, for example 1-3,5 or all. Up to 50 pages without credits, up to 300 with credits. |
| `ocr_language` | Language of scanned pages: "auto" (detected on the first scanned page) or "deu", "eng", "spa", "fra", joined with + as in "deu+eng". Default: auto. |

A 202 response means the conversion is still running: at once without the wait parameter, after 30 seconds with it. Fetch links.self with GET until status is finished, then download download_url. If you set a webhook URL for the request or your account, we also call it when the conversion is done. Up to 50 files go into one batch.

## Where your files go

- **Converted on our server**: Conversions run on our server in the EU. Stored files and results are deleted after 24 hours. [Hosting in the privacy policy](https://switchfile.io/privacy#hosting)
- **Without storage: store=false**: The file and the result are processed in memory while the request runs and are not written to our file storage or database. The service that converts them cannot open connections to the internet. In this mode files can be up to 50 MB. Your usage history keeps the time, formats, sizes and credits, never the file name. [Converting without storage](https://switchfile.io/docs/no-store)
- **Data processing agreement**: We sign a data processing agreement (DPA) under Art. 28 GDPR on request. Write to hello@switchfile.io. [Security](https://switchfile.io/security#dpa)

```bash
code=$(curl -s "https://api.switchfile.io/v1/convert?store=false" \
  -o reply -D headers -w "%{http_code}" \
  -H "Authorization: Bearer $SWITCHFILE_API_KEY" \
  -F file=@report.pdf -F to=json)
if grep -qi '^x-incomplete' headers; then
  grep -i '^x-notes' headers  # partial result, left in reply
elif [ "$code" = 200 ] && grep -qi '^content-disposition' headers; then
  mv reply report.json
else
  cat reply  # otherwise the error
fi
```

## Pricing

Free: 20 files/day, up to 50 pages per conversion, free API key
Credit pack: from €7, 500 credits, one-time, no subscription
Monthly: from €4, 500 credits a month, cancel at any time
PDF to JSON: 1 credit per started minute of conversion time, at least 1 per file.
Up to 300 pages with credits.
A file that is done within a minute uses 1 credit, which costs €0.0043 to €0.014 depending on the plan or pack.
Add ?dry_run=1 to a convert request to see the credits and the price of a file before you convert it. [Cost before converting](https://switchfile.io/docs/simple-api#dry-run)
[Pricing](https://switchfile.io/pricing)

## SDKs

Client libraries and integrations: [SDK overview](https://switchfile.io/developers#sdks).

## Questions

### What are the limits?

Without credits a PDF can have up to 50 pages, with credits up to 300. For a longer PDF, convert it in parts with the pages option. Files can be up to 1 GB. A file sent in the request can be up to 100 MB; larger files go through an upload, which the SDKs do on their own. One conversion can run for up to 5 minutes. Without storage (store=false), files can be up to 50 MB.

### What does a table look like in the JSON?

A block with "type": "table" and its size in rows and cols. header_rows gives the number of header rows where it is known, bbox the position on the page. Each entry in cells has its row and col next to its text. Empty cells are left out, and later 1.x versions of the schema only add fields. A table with a single column comes back as one paragraph per row.

### Does it find tables without lines?

Yes. source tells you how a table was found: ruled for a table drawn with lines, layout for one without lines.

### How do I extract tables from a PDF in Python?

Convert the PDF with to=json through the Python SDK, then go through the blocks of each page and take those with "type": "table". Each cell has its row and col, so a table becomes a list of rows in a few lines.

### Where does it get tables wrong?

Charts are not tables and do not become cells. A number like 1.234 can be read in two ways; it is read the way the other numbers of the table are written, so compare value with text where such a column matters. There are no confidence scores.

### Can I get an Excel workbook instead?

Yes. Send to=xlsx, and each table arrives in its own worksheet cells. to=md returns the tables as Markdown pipe tables.

### How long do you keep my files?

A stored conversion keeps the file and the result for 24 hours, then both are deleted. With store=false no file is stored: the result comes back in the response, and only an entry with time, formats, sizes and credits stays in your usage history for 400 days.
