aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJán Jančár2022-11-09 15:12:37 +0100
committerGitHub2022-11-09 15:12:37 +0100
commit4e63b9d555bcae0ce75ed5239e3c3aef9fcdba8f (patch)
tree458894006330ff6aadca2e92d9cdddb5ec3d2b5f
parent4d4a1b61f8e77ee77d17eb129086ebed7ecb94ac (diff)
parent3629ade9db036bb94fa1d4551dcb5c1ebb2a241f (diff)
downloadsec-certs-4e63b9d555bcae0ce75ed5239e3c3aef9fcdba8f.tar.gz
sec-certs-4e63b9d555bcae0ce75ed5239e3c3aef9fcdba8f.tar.zst
sec-certs-4e63b9d555bcae0ce75ed5239e3c3aef9fcdba8f.zip
Merge pull request #280 from crocs-muni/fix/ocr-page-order
Fix OCR page order issue.
-rw-r--r--sec_certs/utils/pdf.py3
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