Extract tables API
Use Extract tables from your code: send the file and get the tables back.
At a glance
- Takes
- PDF or JPG or PNG or TIFF or HEIC or WebP
- Makes
- XLSXOne file or several
- Costs
- 1 credit per page with a table; nothing with a test key, nothing when it fails
- Files
- One a job
- File size
- Up to 1 MB with a test key; 100 MB on Free, up to 5 GB on API Scale
- Engine
- PDF to Office engine (Stirling Office Convert)
Each file’s layout is checked before it converts (a scan, a phone photo or a page in columns, for example). A kind of document this conversion doesn’t take yet ends the job as unsupported_document, with a message that says which, and costs nothing.
Convert a file
Send the file to POST /v1/convert, naming the conversion, with an API key from the dashboard. It can make several files, so the example asks for the job (Accept: application/json), which lists a download URL for each.
curl "https://api.formatjet.com/v1/convert?conversion=extract-tables" \
-H "Authorization: Bearer $FORMATJET_API_KEY" \
-H "Accept: application/json" \
-F file=@input.pdfTypeScript
import { readFile, writeFile } from 'node:fs/promises';
const form = new FormData();
form.append('file', new Blob([await readFile('input.pdf')]), 'input.pdf');
const response = await fetch('https://api.formatjet.com/v1/convert?conversion=extract-tables', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.FORMATJET_API_KEY}`, Accept: 'application/json' },
body: form,
});
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
// The answer is the job: one download URL per file.
const job = (await response.json()) as { outputs: { filename: string; url: string }[] };
for (const output of job.outputs) {
const file = await fetch(output.url);
await writeFile(output.filename, new Uint8Array(await file.arrayBuffer()));
}Python
import os
import requests
files = {"file": open("input.pdf", "rb")}
response = requests.post(
"https://api.formatjet.com/v1/convert",
params={"conversion": "extract-tables"},
headers={"Authorization": f"Bearer {os.environ['FORMATJET_API_KEY']}", "Accept": "application/json"},
files=files,
timeout=60,
)
response.raise_for_status()
# The answer is the job: one download URL per file.
for output in response.json()["outputs"]:
with open(output["filename"], "wb") as file:
file.write(requests.get(output["url"], timeout=60).content)The quickstart makes a test key and runs a request like this one. Requests take up to 25 MB; for larger files, files at a URL or a webhook when it’s done, make a job.
Options
Send them as JSON: options in the query of POST /v1/convert, or in the job’s step. Every one is optional.
| Option | Takes | Default | What it does |
|---|---|---|---|
format | "xlsx" | "csv" | "json" | "xlsx" | Save as |