rasgapdf 0.2.1__tar.gz → 0.2.2__tar.gz
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.
- {rasgapdf-0.2.1 → rasgapdf-0.2.2}/PKG-INFO +1 -1
- {rasgapdf-0.2.1 → rasgapdf-0.2.2}/pyproject.toml +1 -1
- {rasgapdf-0.2.1 → rasgapdf-0.2.2}/rasgapdf/__init__.py +46 -32
- {rasgapdf-0.2.1 → rasgapdf-0.2.2}/rasgapdf/rasgapdf.dll +0 -0
- {rasgapdf-0.2.1 → rasgapdf-0.2.2}/rasgapdf.egg-info/PKG-INFO +1 -1
- {rasgapdf-0.2.1 → rasgapdf-0.2.2}/README.md +0 -0
- {rasgapdf-0.2.1 → rasgapdf-0.2.2}/rasgapdf/librasgapdf.so +0 -0
- {rasgapdf-0.2.1 → rasgapdf-0.2.2}/rasgapdf.egg-info/SOURCES.txt +0 -0
- {rasgapdf-0.2.1 → rasgapdf-0.2.2}/rasgapdf.egg-info/dependency_links.txt +0 -0
- {rasgapdf-0.2.1 → rasgapdf-0.2.2}/rasgapdf.egg-info/top_level.txt +0 -0
- {rasgapdf-0.2.1 → rasgapdf-0.2.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rasgapdf
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Ultra-fast 2D spatial PDF parser powered by pure Rust — extract exact [x0, y0, x1, y1] bounding boxes, text blocks, tables, images & vector paths in milliseconds for RAG & LLMs
|
|
5
5
|
Author: Messias Martins
|
|
6
6
|
Project-URL: Homepage, https://martinsmessias.github.io/rasgapdf/
|
|
@@ -70,7 +70,7 @@ if _lib:
|
|
|
70
70
|
|
|
71
71
|
def version() -> str:
|
|
72
72
|
if not _lib:
|
|
73
|
-
return "0.2.
|
|
73
|
+
return "0.2.2 (unlinked)"
|
|
74
74
|
return _lib.rasgapdf_version().decode("utf-8")
|
|
75
75
|
|
|
76
76
|
def parse_raw(file_path: str) -> Dict[str, Any]:
|
|
@@ -263,47 +263,61 @@ def extract_text(data_or_path: bytes | str) -> str:
|
|
|
263
263
|
data = None
|
|
264
264
|
is_bytes = False
|
|
265
265
|
|
|
266
|
+
res_str = ""
|
|
266
267
|
# 1. Caminho ultra-rápido nativo (se a biblioteca expor rasgapdf_extract_text_bytes)
|
|
267
268
|
if _lib and hasattr(_lib, "rasgapdf_extract_text_bytes"):
|
|
268
269
|
b_data = data if is_bytes else Path(data_or_path).read_bytes()
|
|
269
270
|
res_ptr = _lib.rasgapdf_extract_text_bytes(b_data, len(b_data))
|
|
270
271
|
if res_ptr:
|
|
271
272
|
try:
|
|
272
|
-
|
|
273
|
-
if
|
|
274
|
-
|
|
273
|
+
native_str = ctypes.string_at(res_ptr).decode("utf-8", errors="replace")
|
|
274
|
+
if native_str.strip():
|
|
275
|
+
res_str = native_str
|
|
275
276
|
finally:
|
|
276
277
|
_lib.rasgapdf_free_string(res_ptr)
|
|
277
278
|
|
|
278
279
|
# 2. Fallback robusto via parse_pdf estruturado (preserva blocos e colunas)
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
for
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
280
|
+
if not res_str:
|
|
281
|
+
tmp_path = None
|
|
282
|
+
try:
|
|
283
|
+
if is_bytes:
|
|
284
|
+
import tempfile
|
|
285
|
+
with tempfile.NamedTemporaryFile(suffix=".pdf", delete=False) as tf:
|
|
286
|
+
tf.write(data)
|
|
287
|
+
tmp_path = tf.name
|
|
288
|
+
path_to_parse = tmp_path
|
|
289
|
+
else:
|
|
290
|
+
path_to_parse = str(data_or_path)
|
|
291
|
+
|
|
292
|
+
doc = parse_pdf(path_to_parse, detect_tables=False)
|
|
293
|
+
pages_texts = []
|
|
294
|
+
for page in doc.get("pages", []):
|
|
295
|
+
lines = []
|
|
296
|
+
for block in page.get("text_blocks", []):
|
|
297
|
+
for line in block.get("lines", []):
|
|
298
|
+
text = line.get("text", "")
|
|
299
|
+
if text and text.strip():
|
|
300
|
+
lines.append(text.rstrip())
|
|
301
|
+
if lines:
|
|
302
|
+
pages_texts.append("\n".join(lines))
|
|
303
|
+
res_str = "\n\n".join(pages_texts)
|
|
304
|
+
finally:
|
|
305
|
+
if tmp_path and os.path.exists(tmp_path):
|
|
306
|
+
try:
|
|
307
|
+
os.remove(tmp_path)
|
|
308
|
+
except Exception:
|
|
309
|
+
pass
|
|
310
|
+
|
|
311
|
+
# Normalização nativa de whitespace
|
|
312
|
+
if res_str:
|
|
313
|
+
import re
|
|
314
|
+
lines = [line.rstrip() for line in res_str.splitlines()]
|
|
315
|
+
joined = "\n".join(lines)
|
|
316
|
+
res_str = re.sub(r"\n{3,}", "\n\n", joined).strip()
|
|
317
|
+
if res_str:
|
|
318
|
+
res_str += "\n"
|
|
319
|
+
|
|
320
|
+
return res_str
|
|
307
321
|
|
|
308
322
|
|
|
309
323
|
def extract_images_bytes(data: bytes, output_dir: str) -> Dict[str, Any]:
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rasgapdf
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Ultra-fast 2D spatial PDF parser powered by pure Rust — extract exact [x0, y0, x1, y1] bounding boxes, text blocks, tables, images & vector paths in milliseconds for RAG & LLMs
|
|
5
5
|
Author: Messias Martins
|
|
6
6
|
Project-URL: Homepage, https://martinsmessias.github.io/rasgapdf/
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|