forked from etecnos/pdfeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtables.py
45 lines (28 loc) · 895 Bytes
/
tables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import tabula
import tkinter as tk
from tkinter import filedialog
def tables():
# Open file explorer
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename(
title="Select the a PDF file",
filetypes=[("PDF files", "*.pdf")]
)
# Check if a valid file was selected
if file_path:
print(f"Selected file path: {file_path}")
else:
print("No file selected")
error = False
# Check weather the file given includes tables (beta)
try:
tables = tabula.read_pdf(file_path, pages="all")
# Load the tables inside a txt file
with open("tables.txt", 'w') as file:
for i in range(len(tables)):
file.write(str(tables[i]) + "\n\n\n\n\n")
except:
print("error")
error = True
return error