New Tool Radar

AI PDF

How to Extract a Table from an OCRed PDF with Camelot

Extract a ruled table from a scanned PDF with Camelot lattice mode after OCR has added the text layer.

Schematic illustration of Camelot extraction: OCR the scan first, read the table with lattice mode, and check the parsing report.

Camelot reads tables in two modes: lattice mode uses the drawn lines of a ruled table, and stream mode uses the gaps between words. Both modes need text in the PDF, so a scan must be OCRed first. This guide extracts one ruled table with lattice mode.

Prerequisites

Python, camelot-py installed, Java for the older versions, OCRmyPDF for the OCR step, and a scanned PDF with a ruled 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 Camelot lattice mode

Run camelot.read_pdf with flavor lattice on the OCRed PDF. Expected result: one table is returned with a parsing report.

3. Check the table against the printed page

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

4. Check the parsing report accuracy

Read the accuracy figure in the parsing report. Expected result: the report shows an accuracy above 90 for the table.

Practice check: fictional catering order, three-row ruled table

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

Item Amount
Sandwiches, 20 units 45.00
Drinks, 30 units 22.50
Cakes, 4 units 18.00
Total 85.50

Expected result. Camelot returns the three rows, which add to 85.50, and the parsing report shows an accuracy above 90.

Limits

  • Lattice mode needs drawn lines; a table without borders needs stream mode instead, and a scan that OCR read badly gives Camelot bad text either way.
  • UNTESTED – no OCR tool or AI tool was run; all results above are expected results. The practice file is fictional.

Sources

See all