pdf-to-csv-table-extractor 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pdf_table_extractor/__init__.py +90 -0
- pdf_table_extractor/backends/__init__.py +25 -0
- pdf_table_extractor/backends/base.py +49 -0
- pdf_table_extractor/backends/opencv_backend.py +755 -0
- pdf_table_extractor/cli.py +732 -0
- pdf_table_extractor/cv_tables.py +690 -0
- pdf_table_extractor/debug_viz.py +182 -0
- pdf_table_extractor/exporter.py +173 -0
- pdf_table_extractor/hardware.py +349 -0
- pdf_table_extractor/languages.py +1361 -0
- pdf_table_extractor/models.py +530 -0
- pdf_table_extractor/pdf_loader.py +777 -0
- pdf_table_extractor/pipeline.py +207 -0
- pdf_table_extractor/preprocess.py +172 -0
- pdf_table_extractor/py.typed +1 -0
- pdf_table_extractor/schema.py +1004 -0
- pdf_to_csv_table_extractor-1.0.0.dist-info/METADATA +613 -0
- pdf_to_csv_table_extractor-1.0.0.dist-info/RECORD +21 -0
- pdf_to_csv_table_extractor-1.0.0.dist-info/WHEEL +4 -0
- pdf_to_csv_table_extractor-1.0.0.dist-info/entry_points.txt +4 -0
- pdf_to_csv_table_extractor-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Modern PDF & image table extraction library with schema-matched multi-table grouping."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from importlib import metadata as _importlib_metadata
|
|
6
|
+
|
|
7
|
+
from pdf_table_extractor.backends import BACKEND_NAMES, TableExtractionBackend, get_backend
|
|
8
|
+
from pdf_table_extractor.hardware import (
|
|
9
|
+
HardwareReport,
|
|
10
|
+
ResolvedAccelerator,
|
|
11
|
+
gpu_install_hints,
|
|
12
|
+
probe_hardware,
|
|
13
|
+
resolve_accelerator,
|
|
14
|
+
)
|
|
15
|
+
from pdf_table_extractor.languages import (
|
|
16
|
+
LANGUAGE_ENTRY_POINT_GROUP,
|
|
17
|
+
LanguagePack,
|
|
18
|
+
LanguageSpec,
|
|
19
|
+
LanguageStatus,
|
|
20
|
+
add_custom_language,
|
|
21
|
+
get_languages_dir,
|
|
22
|
+
install_language,
|
|
23
|
+
install_language_pack_from_path,
|
|
24
|
+
list_languages,
|
|
25
|
+
parse_language_spec,
|
|
26
|
+
register_language,
|
|
27
|
+
remove_language,
|
|
28
|
+
unregister_language,
|
|
29
|
+
)
|
|
30
|
+
from pdf_table_extractor.models import (
|
|
31
|
+
BoundingBox,
|
|
32
|
+
ExtractedTable,
|
|
33
|
+
ExtractionConfig,
|
|
34
|
+
ExtractionResult,
|
|
35
|
+
PageImage,
|
|
36
|
+
TableGroup,
|
|
37
|
+
TableSchema,
|
|
38
|
+
TableSourceRef,
|
|
39
|
+
)
|
|
40
|
+
from pdf_table_extractor.pdf_loader import (
|
|
41
|
+
SUPPORTED_IMAGE_EXTENSIONS,
|
|
42
|
+
InputSource,
|
|
43
|
+
load_input_pages,
|
|
44
|
+
load_pdf_pages,
|
|
45
|
+
)
|
|
46
|
+
from pdf_table_extractor.pipeline import extract_pdf_tables, extract_tables
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
__version__ = _importlib_metadata.version("pdf-to-csv-table-extractor")
|
|
50
|
+
except _importlib_metadata.PackageNotFoundError: # pragma: no cover
|
|
51
|
+
__version__ = "0.0.0+unknown"
|
|
52
|
+
|
|
53
|
+
__all__ = [
|
|
54
|
+
"BACKEND_NAMES",
|
|
55
|
+
"LANGUAGE_ENTRY_POINT_GROUP",
|
|
56
|
+
"SUPPORTED_IMAGE_EXTENSIONS",
|
|
57
|
+
"BoundingBox",
|
|
58
|
+
"ExtractedTable",
|
|
59
|
+
"ExtractionConfig",
|
|
60
|
+
"ExtractionResult",
|
|
61
|
+
"HardwareReport",
|
|
62
|
+
"InputSource",
|
|
63
|
+
"LanguagePack",
|
|
64
|
+
"LanguageSpec",
|
|
65
|
+
"LanguageStatus",
|
|
66
|
+
"PageImage",
|
|
67
|
+
"ResolvedAccelerator",
|
|
68
|
+
"TableExtractionBackend",
|
|
69
|
+
"TableGroup",
|
|
70
|
+
"TableSchema",
|
|
71
|
+
"TableSourceRef",
|
|
72
|
+
"__version__",
|
|
73
|
+
"add_custom_language",
|
|
74
|
+
"extract_pdf_tables",
|
|
75
|
+
"extract_tables",
|
|
76
|
+
"get_backend",
|
|
77
|
+
"get_languages_dir",
|
|
78
|
+
"gpu_install_hints",
|
|
79
|
+
"install_language",
|
|
80
|
+
"install_language_pack_from_path",
|
|
81
|
+
"list_languages",
|
|
82
|
+
"load_input_pages",
|
|
83
|
+
"load_pdf_pages",
|
|
84
|
+
"parse_language_spec",
|
|
85
|
+
"probe_hardware",
|
|
86
|
+
"register_language",
|
|
87
|
+
"remove_language",
|
|
88
|
+
"resolve_accelerator",
|
|
89
|
+
"unregister_language",
|
|
90
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Table extraction backend interface and RapidOCR OpenCV engine factory."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pdf_table_extractor.backends.base import TableExtractionBackend
|
|
6
|
+
from pdf_table_extractor.backends.opencv_backend import OpenCVBackend
|
|
7
|
+
|
|
8
|
+
BACKEND_NAMES: tuple[str, ...] = ("opencv",)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_backend(name: str = "opencv") -> TableExtractionBackend:
|
|
12
|
+
"""Instantiate the table extraction backend by name."""
|
|
13
|
+
key = name.lower().strip()
|
|
14
|
+
if key == "opencv":
|
|
15
|
+
return OpenCVBackend()
|
|
16
|
+
available = ", ".join(BACKEND_NAMES)
|
|
17
|
+
raise ValueError(f"Unknown backend {name!r}. Available backends: {available}")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"BACKEND_NAMES",
|
|
22
|
+
"OpenCVBackend",
|
|
23
|
+
"TableExtractionBackend",
|
|
24
|
+
"get_backend",
|
|
25
|
+
]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Base protocol and shared helpers for pluggable table extraction backends."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Protocol
|
|
6
|
+
|
|
7
|
+
from pdf_table_extractor.hardware import ResolvedAccelerator
|
|
8
|
+
from pdf_table_extractor.models import BoundingBox, ExtractedTable, ExtractionConfig, PageImage
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TableExtractionBackend(Protocol):
|
|
12
|
+
"""Protocol implemented by all table extraction backends."""
|
|
13
|
+
|
|
14
|
+
name: str
|
|
15
|
+
|
|
16
|
+
def extract(
|
|
17
|
+
self,
|
|
18
|
+
page: PageImage,
|
|
19
|
+
config: ExtractionConfig,
|
|
20
|
+
accelerator: ResolvedAccelerator,
|
|
21
|
+
) -> list[ExtractedTable]:
|
|
22
|
+
"""Extract all detected tables from a single page image."""
|
|
23
|
+
...
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def compute_column_x_spans(
|
|
27
|
+
cell_bboxes: list[list[BoundingBox | None]],
|
|
28
|
+
) -> list[tuple[float, float]] | None:
|
|
29
|
+
"""Compute normalized horizontal [x1, x2] bounds per column from cell bounding boxes."""
|
|
30
|
+
if not cell_bboxes:
|
|
31
|
+
return None
|
|
32
|
+
num_cols = max((len(row) for row in cell_bboxes), default=0)
|
|
33
|
+
if num_cols == 0:
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
spans: list[tuple[float, float]] = []
|
|
37
|
+
for col_idx in range(num_cols):
|
|
38
|
+
x1s: list[float] = []
|
|
39
|
+
x2s: list[float] = []
|
|
40
|
+
for row in cell_bboxes:
|
|
41
|
+
if col_idx < len(row):
|
|
42
|
+
box = row[col_idx]
|
|
43
|
+
if box is not None and box.width > 0:
|
|
44
|
+
x1s.append(box.x1)
|
|
45
|
+
x2s.append(box.x2)
|
|
46
|
+
if not x1s:
|
|
47
|
+
return None
|
|
48
|
+
spans.append((min(x1s), max(x2s)))
|
|
49
|
+
return spans
|