New Tool Radar

AI PDF

How to Extract a Table from an OCRed PDF with Tabula

Extract a table from a scanned PDF with Tabula after OCR has added the text layer Tabula needs.

Schematic illustration of Tabula extraction: OCR the scan first, read the table with Tabula, and save it to a spreadsheet.

Tabula reads tables from text-based PDFs, not from scans: it finds table boundaries from whitespace and text positions, so a scanned PDF gives it nothing to read. The route is to OCR the scan first, then run Tabula on the searchable PDF. This guide extracts one table that way.

Prerequisites

Java 8 or later, tabula-py installed, OCRmyPDF or Tesseract for the OCR step, and a scanned PDF with a table. Work on a copy.

Steps

1. OCR the scanned PDF first

Run OCRmyPDF on the scanned PDF to add a text layer. Expected result: the table text becomes selectable in the output PDF.

2. Read the table with Tabula

Run tabula.read_pdf on the OCRed PDF with pages set to all. Expected result: a list of DataFrames is returned, with one table.

3. Check the table against the printed page

Compare the returned table with the printed page row by row. Expected result: the three rows match the printed page.

4. Save the table to a spreadsheet

Write the DataFrame to a spreadsheet file. Expected result: a spreadsheet is created with the three rows.

Practice check: fictional stationery order, three-row table

The table below is fictional practice material. It lists the three rows Tabula must return.

Item Amount
Paper, 10 reams 12.50
Pens, 12 units 8.75
Folders, 6 units 6.20
Total 27.45

Expected result. Tabula returns the three rows, which add to 27.45, and the spreadsheet holds the same three rows.

Limits

  • Tabula only works on text-based PDFs, so a scan that OCR read badly gives Tabula bad text to work with; check the OCR layer first.
  • UNTESTED – no OCR tool or AI tool was run; all results above are expected results. The practice file is fictional.

Sources

See all