diff --git a/paperforge/worker/ocr.py b/paperforge/worker/ocr.py index 85fd188b..92608b72 100644 --- a/paperforge/worker/ocr.py +++ b/paperforge/worker/ocr.py @@ -1819,15 +1819,21 @@ def postprocess_ocr_result(vault: Path, key: str, all_results: list[dict]) -> tu artifacts.blocks_raw.parent.mkdir(parents=True, exist_ok=True) artifacts.blocks_structured.parent.mkdir(parents=True, exist_ok=True) all_raw_blocks = build_raw_blocks_for_result_lines(key, all_results) - write_raw_blocks_jsonl(artifacts.blocks_raw, all_raw_blocks) - # Backfill span_metadata from source PDF (not from OCR engine) source_pdf_path = Path(meta.get("source_pdf", "")) if meta.get("source_pdf") else None if source_pdf_path and source_pdf_path.exists(): - from paperforge.worker.ocr_pdf_spans import backfill_span_metadata_from_pdf + from paperforge.worker.ocr_pdf_spans import ( + backfill_span_metadata_from_pdf, + backfill_missing_text_from_pdf, + ) + # Attach PDF-derived font/geometry evidence first backfill_span_metadata_from_pdf(all_raw_blocks, source_pdf_path) - write_raw_blocks_jsonl(artifacts.blocks_raw, all_raw_blocks) + + # Recover empty OCR text using the same source PDF + backfill_missing_text_from_pdf(all_raw_blocks, source_pdf_path) + + write_raw_blocks_jsonl(artifacts.blocks_raw, all_raw_blocks) structured, doc_structure = build_structured_blocks( all_raw_blocks,