#!/usr/bin/env python3 """OCR the image-only scans of Atari's 1995 developer binder into reference/ocr/. The binder PDFs under reference/src/jaguar-sdk/jaguar/docs/dev/ (fetched by fetch_references.py) have no text layer. The documents cite three of them by page: the Software Reference Manual v2.4, Hardware Bugs & Warnings (26 April 1995) and the Jaguar CD-ROM section. OCR text is a reading aid only: check a number that matters against the page image (pdftoppm -f N -l N -r 90 -png). python3 -I scripts/ocr_scans.py # the three documents, one at a time python3 -I scripts/ocr_scans.py --only 05 # one document by its number Needs ocrmypdf and tesseract. Runs at nice 19 with two jobs: the machine is shared. """ from __future__ import annotations import argparse import subprocess import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] SOURCE = ROOT / "reference" / "src" / "jaguar-sdk" / "jaguar" / "docs" / "dev" OUT = ROOT / "reference" / "ocr" DOCUMENTS = ("03 - Software Reference", "05 - Hardware Bugs & Warnings", "06 - Jaguar CD-ROM") def main() -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("--only", help="document number prefix, e.g. 05") args = parser.parse_args() OUT.mkdir(parents=True, exist_ok=True) status = 0 for name in DOCUMENTS: if args.only and not name.startswith(args.only): continue text = OUT / f"{name}.txt" if text.exists(): print(f"{text.name}: present") continue command = [ "nice", "-n", "19", "ocrmypdf", "--jobs", "2", "--skip-text", "--sidecar", str(text), "--output-type", "pdf", str(SOURCE / f"{name}.pdf"), str(OUT / f"{name}.pdf"), ] print(" ".join(command)) result = subprocess.run(command, check=False) status = status or result.returncode return status if __name__ == "__main__": sys.exit(main())