fix: suppress markdown when all pages have gid-encoded fonts

When every page uses fonts with unresolvable gid-encoded glyphs,
the extracted text is unreliable garbage. Suppress the markdown
output so consumers know to use OCR instead.

Only triggers for gid-encoded fonts specifically, not for other
OCR signals (Identity-H without ToUnicode, template images) where
the text layer may still be partially useful.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Abimael Martell
2026-03-19 18:37:06 -07:00
co-authored by Claude Opus 4.6
parent 587c4bed95
commit 967b70a788
+13 -1
View File
@@ -449,7 +449,9 @@ fn process_document(
(markdown, has_encoding_issues, false)
};
// Add pages with gid-encoded fonts (unresolvable encoding) to OCR list
// Add pages with gid-encoded fonts (unresolvable encoding) to OCR list.
// When ALL pages have gid-encoded fonts, suppress unreliable markdown.
let all_gid = !gid_pages.is_empty() && gid_pages.len() as u32 >= page_count;
let mut pages_needing_ocr = pages_needing_ocr;
if force_ocr_all {
pages_needing_ocr = (1..=page_count).collect();
@@ -464,6 +466,16 @@ fn process_document(
pages_needing_ocr.sort_unstable();
}
let markdown = if all_gid {
log::debug!(
"all {} pages have gid-encoded fonts — suppressing markdown output",
page_count
);
None
} else {
markdown
};
Ok(PdfProcessResult {
pdf_type,
markdown,