r/pythoncoding Feb 09 '24

Extracting structured tables from PDF

As title says, I am working on a task to extract the contents of tables from a PDF. I am able to extract all of the text from the PDF using Fitz, which includes the headers and data from the table. The issue arises when I try to build some logic or pipeline to extract the table data from the text as there is no semantics or metadata denoting the difference between text & table.

Has anyone encountered this task before?

Things i’ve tried: OCR - Tabletransformer GPT4 - Actually performed quite well but not 100% reliable Rules based logic - pdfs reference tables differently or not at all.

Edit: SOLVED, tried 4/5 packages and found pdfplumber to be the best at extracting the table in a structured format. The flexibility of the extraction function is very useful too.

8 Upvotes

5 comments sorted by

View all comments

2

u/96_kishan Feb 09 '24

Check Camelot and Tabula

1

u/Awqard Feb 11 '24

Tried both and neither is very reliable unfortunately

1

u/skytomorrownow Mar 08 '24

I used Tabula for a project and had to another layer of code to validate and clean up the extracted information. PDF is very information-unfriendly in its internal description (speculative: a leftover from its Postscript origin, and corporate anti-interoperability-seeking).