-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtablex.py
More file actions
39 lines (19 loc) · 752 Bytes
/
Copy pathtablex.py
File metadata and controls
39 lines (19 loc) · 752 Bytes
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
import pymupdf
import os
print("Extract Tables\n\n")
filename = input("Filename: ")
output_dir = f"output/{filename.split('.')[0]}"
os.makedirs(output_dir, exist_ok=True)
doc = pymupdf.open(filename)
tbl_strategy = input("Table strategy (“lines” / “lines_strict” / “text”): ") or None
table_count = 0
for page in doc:
ft = page.find_tables(strategy=tbl_strategy)
if(len(ft.tables)>0):
for table in ft.tables:
print(f"Table {table_count}: {len(table.extract())} rows, bbox: {table.bbox}")
pix = page.get_pixmap(dpi=150, clip=table.bbox)
pix.save(f"output/{filename}_table_{table_count}.png")
table_count += 1
doc.close()
#print("Task complete")