docuparse 0.0.1

Document extraction and parsing — PDF text, rendering, and OCR
Documentation
#[derive(Debug, thiserror::Error)]
pub enum ValidationError {
    #[error("file not found: {path}")]
    NotFound { path: String },

    #[error("path is not a file: {path}")]
    NotAFile { path: String },

    #[error("file too small to be a valid PDF ({size} bytes, minimum {min} bytes)")]
    TooSmall { size: u64, min: u64 },

    #[error("file too large ({size_mb} MB, maximum {max_mb} MB)")]
    FileTooLarge { size_mb: u64, max_mb: u64 },

    #[error("invalid PDF — missing %PDF- header")]
    InvalidMagicBytes,

    #[error("io error during validation: {0}")]
    Io(#[from] std::io::Error),
}

#[derive(Debug, thiserror::Error)]
pub enum RenderError {
    #[error("page {page} is out of range (document has {total} pages)")]
    PageOutOfRange { page: u32, total: u32 },

    #[error("failed to render page {page} to bitmap")]
    RenderFailed { page: u32 },

    #[error("failed to encode rendered image")]
    EncodingFailed(#[from] image::ImageError),

    #[error("failed to convert rendered bitmap to image on page {page}")]
    BitmapConversionFailed { page: u32 },
}

#[derive(Debug, thiserror::Error)]
pub enum TextError {
    #[error("failed to extract text from page {page}")]
    ExtractionFailed { page: u32 },

    #[error("page {page} has no text layer")]
    NoTextLayer { page: u32 },
}

#[derive(Debug, thiserror::Error)]
pub enum PdfiumError {
    #[error("failed to initialize PDFium")]
    InitFailed,

    #[error("failed to load PDF '{path}': {reason}")]
    LoadFailed { path: String, reason: String },

    #[error("PDFium internal error: {0}")]
    Internal(String),
}

/// The sole error type that crosses the library boundary.
/// All domain errors compose into this via `#[from]`.
#[derive(Debug, thiserror::Error)]
pub enum PdfError {
    #[error(transparent)]
    Validation(#[from] ValidationError),

    #[error(transparent)]
    Pdfium(#[from] PdfiumError),

    #[error(transparent)]
    Render(#[from] RenderError),

    #[error(transparent)]
    Text(#[from] TextError),
}