From f3c00678b2a253d10efb736134a8fb262c62ccf0 Mon Sep 17 00:00:00 2001 From: Abimael Martell Date: Mon, 9 Mar 2026 14:37:00 -0700 Subject: [PATCH] fix(detector): raise text-ops threshold on pages with images Pages with images AND very few text operators (<10) are image pages with overlay text (headers/footers), not real text pages. This fixes image-heavy PDFs like newspaper ads being misclassified as TextBased. Co-Authored-By: Claude Opus 4.6 --- src/detector.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/detector.rs b/src/detector.rs index 26f2854..da0296b 100644 --- a/src/detector.rs +++ b/src/detector.rs @@ -197,7 +197,12 @@ pub(crate) fn detect_from_document( pages_actually_sampled += 1; let is_image_dominated = analysis.image_count > 10 && analysis.image_count > analysis.text_operator_count * 3; - if analysis.text_operator_count >= config.min_text_ops_per_page + let effective_min_ops = if analysis.has_images || analysis.image_count > 0 { + config.min_text_ops_per_page.max(10) + } else { + config.min_text_ops_per_page + }; + if analysis.text_operator_count >= effective_min_ops && !is_image_dominated && analysis.unique_text_chars >= 5 && !analysis.has_vector_text