Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pdf-to-csv

Extract one or more tables from a PDF and export them as CSV files.

Idea

The project was born from the need to automate the import of tabular data into software that accepts CSV files but not PDFs.

Structure

  1. Read PDF document
  2. Extraction layer (pdfplumber)
  3. Normalization layer (clean rows + detect header once)
  4. DataFrame layer (Polars)
  5. Export into a CSV sheet

Result

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 ';'.

How to launch the script

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

GUI

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.

Requirements

Python version

python>=3.11.0

Packages

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

Known issues

  • Tables sharing the same header are currently merged, even if they represent different logical tables.

About

Tool to convert tabular pdf into a csv

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages