diff options
| author | J08nY | 2022-11-09 13:20:24 +0100 |
|---|---|---|
| committer | J08nY | 2022-11-09 13:20:24 +0100 |
| commit | 3629ade9db036bb94fa1d4551dcb5c1ebb2a241f (patch) | |
| tree | 458894006330ff6aadca2e92d9cdddb5ec3d2b5f | |
| parent | 4d4a1b61f8e77ee77d17eb129086ebed7ecb94ac (diff) | |
| download | sec-certs-3629ade9db036bb94fa1d4551dcb5c1ebb2a241f.tar.gz sec-certs-3629ade9db036bb94fa1d4551dcb5c1ebb2a241f.tar.zst sec-certs-3629ade9db036bb94fa1d4551dcb5c1ebb2a241f.zip | |
Fix OCR page order issue.
Fixes #279.
| -rw-r--r-- | sec_certs/utils/pdf.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/sec_certs/utils/pdf.py b/sec_certs/utils/pdf.py index a40fb18d..8f0e6abf 100644 --- a/sec_certs/utils/pdf.py +++ b/sec_certs/utils/pdf.py @@ -58,7 +58,8 @@ def ocr_pdf_file(pdf_path: Path) -> str: if tes.returncode != 0: raise ValueError(f"tesseract failed: {tes.returncode}") contents = "" - for txt_path in map(Path, glob.glob(str(tmppath / "image*.txt"))): + txt_paths = list(glob.glob(str(tmppath / "image*.txt"))) + for txt_path in map(Path, sorted(txt_paths, key=lambda fname: int(fname[6:-4]))): with txt_path.open("r", encoding="utf-8") as f: contents += f.read() return contents |
