camelot-py 2.0 (pdfium, без Ghostscript/OpenCV), v1.31

This commit is contained in:
2026-06-17 21:31:37 +04:00
parent e613716178
commit 6187e4dee8
3 changed files with 21 additions and 16 deletions
+19 -14
View File
@@ -124,22 +124,27 @@ def _parse_doc(file_bytes: bytes) -> dict:
def _parse_pdf(file_bytes: bytes) -> dict:
result = {"elements": [], "errors": []}
# Попробовать tabula (Java) — точнее таблицы
tables_from_tabula = False
# Попробовать camelot (pdfium, без системных зависимостей)
tables_from_camelot = False
try:
import tabula
tables = tabula.read_pdf(io.BytesIO(file_bytes), pages="all", multiple_tables=True)
for tbl in tables:
rows = [list(tbl.columns)] + tbl.values.tolist()
result["elements"].append({
"type": "table",
"rows": rows,
})
tables_from_tabula = len(tables) > 0
import camelot
for flavor in ("lattice", "stream"):
try:
ctables = camelot.read_pdf(io.BytesIO(file_bytes), pages="all", flavor=flavor)
for ct in ctables:
rows = [list(ct.df.columns)] + ct.df.values.tolist()
result["elements"].append({
"type": "table",
"rows": rows,
"page": ct.page,
})
tables_from_camelot = True
except Exception:
pass
except ImportError:
result["errors"].append("tabula not installed, using pdfplumber")
result["errors"].append("camelot not installed, using pdfplumber")
except Exception as e:
result["errors"].append(f"tabula error: {e}")
result["errors"].append(f"camelot error: {e}")
# pdfplumber: текст + таблицы (если tabula не сработал)
try:
@@ -158,7 +163,7 @@ def _parse_pdf(file_bytes: bytes) -> dict:
"text": line,
"page": pn,
})
if not tables_from_tabula:
if not tables_from_camelot:
tables = page.extract_tables()
for tbl in tables:
if tbl:
+1 -1
View File
@@ -59,7 +59,7 @@
<body>
<div class="topbar">
<img src="{{ url_for('static', filename='nubes-logo.svg') }}" alt="Nubes">
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.30</span></span>
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.31</span></span>
</div>
<div class="content">