Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

PDF tables to CSV files #263

Merged
merged 4 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions System-Automation-Scripts/PDF_Tables_To_CSV/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Vscode files
.vscode

# Sample Files
sample.pdf
sample2.pdf

# Python
__pycache__
22 changes: 22 additions & 0 deletions System-Automation-Scripts/PDF_Tables_To_CSV/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# PDF to CSV
This script will convert the tables in the PDF file into CSV files. Each CSV file has one table from the PDF and the number of CSV equal to the number of tables in the PDF.

# Requirements
`pip install tabula-py, pandas`

# How to use?
Just use the following command while executing the scrpit:

`python app.py location_of_pdf pages`

Pages have two options:
- 'all' will extract tables from whole PDF
- specific page (ex 1,2,54..) will extract table from that page

Example:
- `python app.py sample.pdf all`
- `python app.py sample2.pdf 45`

# Preview

![](preview.gif)
19 changes: 19 additions & 0 deletions System-Automation-Scripts/PDF_Tables_To_CSV/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import tabula
import pandas as pd
import sys

def extract(path, number_pages):
tables = tabula.read_pdf(path, multiple_tables=True, pages=number_pages)
count = 1
if len(tables)!=0:
for table in tables:
print
print(f"Saving file -{count}")
table.to_csv(f'Table- {count}.csv')
count += 1
print("All tables saved as seperate files !")
else:
print("No tables found !")

if __name__ == "__main__":
extract(sys.argv[1], sys.argv[2])
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.