Skip to content

Fail PDFs with scanned or garbled pages instead of converting them with pages missing - #6

Merged
mpiorowski merged 4 commits into
mainfrom
needs-ocr-and-limits
Nov 24, 2026
Merged

mpiorowski merged 4 commits into
mainfrom
needs-ocr-and-limits

Conversation

@mpiorowski

@mpiorowski mpiorowski commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

anydoc checks only eight pages of a PDF for scans and ignores a scan with a few lines of text over it, so a statement with one scanned page converted to markdown that looked complete but was missing that page. The CLI now runs pdf-inspector itself on every page, treats garbled text layers as failures too, and gives every outcome the Elixir caller handles differently its own exit code, plus a timeout and an opt-in mode that skips unreadable pages and lists them. In return, some PDFs go to the paid OCR parser when they didn't need to, such as a logo cover page or a short receipt with a blank back.

Footprint

  • Containment: one binary. Its public surface is the CLI flags and exit codes, and both change. Three new optional flags default to the old behaviour. The exit codes do not (see Review focus).
  • Boundaries crossed: adds a direct pdf-inspector dependency and bumps anydoc to 0.2, which drops calamine and moves zip to 9.x. Untouched: stdout/stderr still never carry document content, and non-PDF formats still go through anydoc unchanged.
  • Gating and revert: no flag gates the stricter PDF check. Reverting means shipping the previous binary to the caller.

Review focus

  • Exit code contract: Encrypted and ResourceLimit moved from 2 to 5 and 6, and scanned PDFs moved from 2 Unsupported to 3. The Elixir caller must learn the new codes before it picks up this binary. See README.md.
  • PDFs no longer go through anydoc's PDF path. This copies that path with stricter settings, so an anydoc fix will not reach PDFs automatically. See src/main.rs.
  • The OCR thresholds are a judgement call: under ten text runs on an image page counts as a scan, and one replacement character fails the whole document. See src/main.rs.

Testing

  • Automated: integration tests cover a scanned page past anydoc's eight-page sample, a scan with a few lines stamped over it, both kinds of garbled text, skip mode with its list of unread pages, a skip-mode PDF with no text at all, the short-receipt case, an encrypted fixture, the timeout, and flag validation. All 21 pass on CI with the pinned Rust 1.88, next to format, Clippy with warnings as errors, the locked release build and cargo deny. None were run locally.
  • Manual: the code as it is now has not been run by hand. An earlier build of this branch, from before the review fixes, ran inside Jump's local app for Jump-App/Jump#34540: scanned and mixed PDFs fell back to the OCR parser as needs_ocr, a PDF with a garbled page as garbled_text, and a password-protected PDF was cancelled as unreadable. That Jump branch already matches on the new exit codes.

🤖 Generated with Claude Code

@mpiorowski mpiorowski changed the title Refuse PDFs that would convert incomplete: scanned pages, garbled text, passwords Refuse PDFs with scanned pages or garbled text, and add timeout and skip flags Nov 24, 2026
…it point, markdown written last, docs match anydoc 0.2
@mpiorowski mpiorowski changed the title Refuse PDFs with scanned pages or garbled text, and add timeout and skip flags Fail PDFs with scanned or garbled pages instead of converting them with pages missing Nov 24, 2026
@mpiorowski mpiorowski added the polished Simplified, reviewed and green label Nov 24, 2026
@mpiorowski
mpiorowski requested a review from a team November 24, 2026 13:41

@sabit990928 sabit990928 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good on paper

@mpiorowski mpiorowski closed this Nov 24, 2026
@mpiorowski mpiorowski reopened this Nov 24, 2026
@mpiorowski
mpiorowski merged commit bb23f12 into main Nov 24, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

polished Simplified, reviewed and green

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants