pdf-untangle 0.0.1

Untangle garbled PDF text: layout-aware extraction that reconstructs reading order, strips page furniture, and splits documents into structured, citable sections
Documentation
//! Layer 1 — PDF → positioned text runs.
//!
//! Backends are pluggable behind [`TextSource`] so Layers 2–3 never know which
//! extraction engine produced the runs. Two are planned (feature-gated):
//! `backend-pdfium` (Google PDFium via pdfium-render; best quality, native lib)
//! and `backend-pure` (lopdf/pdf-extract; zero native dependencies). The
//! Phase-1 decision gate picks the default by comparing both on the corpus.

use anyhow::Result;

/// One run of text as placed on a page: contiguous glyphs sharing position
/// and style. The atom Layer 2 works from.
#[derive(Debug, Clone, PartialEq)]
pub struct TextRun {
    pub text: String,
    /// Page-space bounding box, points, origin bottom-left: (x0, y0, x1, y1).
    pub bbox: (f32, f32, f32, f32),
    pub font_size: f32,
    pub bold: bool,
    pub italic: bool,
    /// 0-based page index this run belongs to.
    pub page: usize,
}

/// A page's dimensions plus every run on it, in source (not reading) order.
#[derive(Debug, Clone)]
pub struct PageRuns {
    pub width: f32,
    pub height: f32,
    pub runs: Vec<TextRun>,
}

/// An extraction backend: opens PDF bytes and yields per-page runs.
pub trait TextSource {
    fn pages(&self, pdf_bytes: &[u8]) -> Result<Vec<PageRuns>>;
}

/// Extract positioned runs from PDF bytes with the default backend.
pub fn runs(pdf_bytes: &[u8]) -> Result<Vec<PageRuns>> {
    let _ = pdf_bytes;
    anyhow::bail!("Layer 1 backends land in Phase 1 (see docs/DESIGN.md)")
}