Extract one or more tables from a PDF and export them as CSV files.
The project was born from the need to automate the import of tabular data into software that accepts CSV files but not PDFs.
- Read PDF document
- Extraction layer (pdfplumber)
- Normalization layer (clean rows + detect header once)
- DataFrame layer (Polars)
- Export into a CSV sheet
From a PDF file, the script can extract one or more tables.
If the PDF contains:
- one table → one CSV
- multiple independent tables → multiple CSVs
- tables split across pages with the same header → merged into a single CSV
The basename of the resulting csv file is the same of the input PDF. However, if the PDF document presents more than one table, multiple csv files are generated with the same basename, but with different suffix (e.g., input is 'doc.pdf', the output may be 'doc_1.csv', 'doc_2.csv'). The separator of the csv file is ';'.
It is possible to launch the script in two different ways: via CLI and via GUI.
To launch the script on command line
python cli.py -i path/to/pdf_file.pdf -o output_directory
To launch the script on GUI:
python main.py
The interface presents
- a section to select the input PDF file
- a section to select the output directory for the resulting csv file
For both of them, there is the possibility
- to paste the path
- to browse the directories and select the input file / output directory.
python>=3.11.0
In requirements.txt you find the packages useful to run this project (pyinstaller is optional, this package is useful to extract the binary of the Python script).
pip install -r requirements.txt
- Tables sharing the same header are currently merged, even if they represent different logical tables.