Inkspan › Guides › How to extract tables from a PDF in Node.js

How to extract tables from a PDF in Node.js

Getting tabular data out of a PDF is where most document pipelines break, because the usual failure is not an error — it is a plausible-looking table with a column quietly shifted. The /v1/extract/tables endpoint returns detected tables as JSON rows together with a confidence score and a review_recommended flag.

Detection first looks for ruling lines. When a table has no borders, it falls back to reconstructing structure from word coordinates, which is robust to font and rendering differences. The confidence score reflects which path succeeded and how cleanly — so you can route low-confidence documents to a human instead of writing wrong data to your database.

Also in: cURL · Python

Node.js example

import fs from 'node:fs';

const fd = new FormData();
fd.append('file', new Blob([fs.readFileSync('input.pdf')]), 'input.pdf');

const res = await fetch('https://api.inkspan.dev/v1/extract/tables', {
  method: 'POST',
  headers: { 'X-API-Key': process.env.INKSPAN_KEY },
  body: fd,
});
if (!res.ok) throw new Error(await res.text());
console.log(await res.json());

Request parameters

NameTypeRequiredDescription
filefileyesThe PDF to extract tables from.

Response

Returns application/json:

{
  "table_count": 1,
  "tables": [
    {
      "page": 1,
      "rows": [
        [
          "Item",
          "Qty",
          "Price"
        ],
        [
          "Widget",
          "5",
          "$10"
        ]
      ]
    }
  ],
  "confidence": 0.95,
  "review_recommended": false
}

Things that catch people out

Errors

StatusMeaningFix
401Invalid or missing API keySend your key in the X-API-Key header.
402Monthly quota exceededThe response reports used/quota. Upgrade at inkspan.dev/#pricing.
422Missing or invalid parameterCheck required fields in the table above — the body names the offending field.

Failed requests do not count against your quota; only successful ones are metered.

Frequently asked questions

What does the confidence score mean?

It reflects how cleanly table structure was recovered — ruled tables detected directly score highest, coordinate-reconstructed tables lower. Use review_recommended as the decision boundary rather than picking your own threshold.

Does it work on borderless tables?

Yes. When no ruling lines are found, structure is reconstructed from word positions, typically with a lower confidence score.

Can I get the output as CSV?

The response is JSON rows, which map directly onto a CSV writer in a couple of lines on your side.

Get a free API key →

Related Extract guides: extract text from a PDF