torchcell.literature.ocr_pdf

ocr_pdf(pdf_path: str | Path, *, backend: str = 'pipeline', lang: str = 'en', method: str = 'auto', device_mode: str | None = None, dpi: int | None = None, timeout: int = 3600) → Path[source]

OCR one PDF to markdown next to it (<stem>.pdf -> <stem>.md).

Runs the standalone _run_mineru.py under the isolated MinerU env. The runner writes <stem>.md (plus its figures in images_dir_for() and the layout JSON) into the PDF’s directory. Then the processing record (ProcessingRecord: the MinerU version and effective DPI the runner reported, the arguments, the exact command and the PDF’s sha256) is written to <stem>_ocr_provenance.json beside the markdown, where build_manifest attaches it to the markdown’s record. Raises PdfNotFoundError before starting MinerU when the PDF is not a file, RuntimeError on a non-zero exit – no silent skip.

Parameters:
  • pdf_path – PDF to OCR.

  • backend – MinerU backend (pipeline | vlm-auto-engine | hybrid-auto-engine).

  • lang – OCR language hint passed to MinerU.

  • method – MinerU parse method (auto | txt | ocr).

  • device_mode – cuda | cpu; defaults to $MINERU_DEVICE_MODE or “cuda”.

  • dpi – Page rasterization DPI; defaults to $TORCHCELL_MINERU_DPI or MinerU’s 200. Raising this (e.g. 350) recovers rows that low resolution drops.

  • timeout – Subprocess timeout (s). First run downloads models – be generous.

Returns:

Path to the produced markdown file.