Skip to content

Add OCR routing integration guide with confidence threshold and Mixed-PDF handling examples #248

Description

@yulinlina

Description

pdf-inspector advertises smart classification and per-page OCR routing, but the README does not currently provide clear guidance on how users should interpret the confidence score, choose a threshold, or handle Mixed PDFs in production workflows.

A dedicated integration guide would help users make reliable routing decisions such as:

  • When a PDF can be processed locally without OCR.
  • When specific pages should be sent to an OCR service.
  • How to handle low-confidence or mixed-content documents.
  • What thresholds are reasonable for different use cases.

Motivation

One of the main goals of this library is to help applications skip expensive OCR services for PDFs that do not need them. However, in real-world integrations, users need more than the raw classification output.

For example, developers may have questions like:

  • Is a confidence score of 0.65 safe to treat as text-based?
  • Should Mixed documents always trigger OCR?
  • How should per-page routing results be combined with external OCR providers?
  • What happens if text extraction succeeds but the confidence is low?
  • Should the threshold be stricter for archival workflows versus search indexing?

Without documented guidance, users may choose inconsistent thresholds, accidentally route too many pages to OCR, or incorrectly treat scanned/mixed PDFs as fully text-based.

Proposed Solution

Add a documentation page such as docs/ocr-routing.md that explains how to use the classification and routing APIs effectively.

The guide could include:

  1. Explanation of classification results

    • TextBased
    • Scanned
    • ImageBased
    • Mixed
    • Meaning of confidence scores
    • Meaning of per-page routing decisions
  2. Recommended default thresholds

    • Example: high-confidence text-based processing
    • Example: conservative OCR fallback
    • Example: balanced cost/accuracy mode
  3. Language-specific examples

    • Rust
    • Python
    • Node.js
    • WebAssembly, if applicable
  4. Common routing patterns

    • Process locally if confidence is above threshold.
    • Send only selected pages to OCR.
    • Fall back to full-document OCR for low-confidence or mixed PDFs.
    • Combine pdf-inspector with external OCR providers.
  5. Edge cases and caveats

    • Password-protected PDFs
    • PDFs with embedded images but extractable text
    • Poor-quality scans
    • Mixed pages containing both text and images
    • Documents where text extraction succeeds but reading order is unreliable
  6. Optional helper pattern

    • A small example utility such as should_use_ocr(page_result, threshold) could be included in documentation without necessarily changing the core API.

Alternatives Considered

  • Leave the current API as-is and expect users to infer routing behavior from the raw fields.
  • Add a higher-level routing API inside the library, but that may be a larger design decision.
  • Provide examples only in the README, though a dedicated guide would be easier to maintain and discover.

A documentation-first approach is low-risk, improves developer experience, and helps users get value from the existing classification features without requiring breaking API changes.


🤖 Suggested by GitHub Trend-Hacking Pipeline

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions