чистый pdfplumber (camelot/tabula дают мусор), v1.36
This commit is contained in:
@@ -123,30 +123,6 @@ def _parse_doc(file_bytes: bytes) -> dict:
|
||||
|
||||
def _parse_pdf(file_bytes: bytes) -> dict:
|
||||
result = {"elements": [], "errors": []}
|
||||
|
||||
# Попробовать camelot (pdfium, без системных зависимостей)
|
||||
tables_from_camelot = False
|
||||
try:
|
||||
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("camelot not installed, using pdfplumber")
|
||||
except Exception as e:
|
||||
result["errors"].append(f"camelot error: {e}")
|
||||
|
||||
# pdfplumber: текст + таблицы (если tabula не сработал)
|
||||
try:
|
||||
import pdfplumber
|
||||
with pdfplumber.open(io.BytesIO(file_bytes)) as pdf:
|
||||
@@ -163,7 +139,6 @@ def _parse_pdf(file_bytes: bytes) -> dict:
|
||||
"text": line,
|
||||
"page": pn,
|
||||
})
|
||||
if not tables_from_camelot:
|
||||
tables = page.extract_tables()
|
||||
for tbl in tables:
|
||||
if tbl:
|
||||
@@ -174,7 +149,6 @@ def _parse_pdf(file_bytes: bytes) -> dict:
|
||||
})
|
||||
except Exception as e:
|
||||
result["errors"].append(f"pdfplumber: {e}")
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -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.35</span></span>
|
||||
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.36</span></span>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
|
||||
Reference in New Issue
Block a user