Skip to content
LiteParse

API Reference

API reference for the liteparse Rust crate. Types are shared across Node.js, Python, and WASM bindings.

LiteParse — open-source PDF parsing with spatial text extraction, OCR, and bounding boxes.

This crate is the core Rust library. Language bindings for Node.js, Python, and WebAssembly re-export the same types with language-idiomatic wrappers.

Configuration for LiteParse document parsing.

pub struct LiteParseConfig {
pub ocr_language: String,
pub ocr_enabled: bool,
pub ocr_server_url: Option<String>,
pub tessdata_path: Option<String>,
pub max_pages: usize,
pub target_pages: Option<String>,
pub dpi: f32,
pub output_format: OutputFormat,
pub preserve_very_small_text: bool,
pub password: Option<String>,
pub quiet: bool,
pub num_workers: usize,
}
NameTypeDocumentation
ocr_languageStringOCR language code (Tesseract format: “eng”, “fra”, “deu”, etc.).
ocr_enabledboolWhether OCR is enabled. When true, runs on text-sparse pages and embedded images.
ocr_server_urlOption<String>HTTP OCR server URL (uses Tesseract if not provided)
tessdata_pathOption<String>Path to tessdata directory. Falls back to TESSDATA_PREFIX env var if not set.
max_pagesusizeMaximum number of pages to parse.
target_pagesOption<String>Specific pages to parse (e.g., “1-5,10,15-20”). None means all pages.
dpif32DPI for rendering pages (used for OCR and screenshots).
output_formatOutputFormatOutput format.
preserve_very_small_textboolKeep very small text that would normally be filtered out.
passwordOption<String>Password for encrypted/protected documents.
quietboolSuppress progress output.
num_workersusizeNumber of concurrent OCR workers. Defaults to (number of CPU cores - 1), minimum 1.

Attributes:

  • Other("#[serde(rename_all = \"lowercase\")]")

Supported output formats.

pub enum OutputFormat {
Json,
Text,
}
pub enum LiteParseError {
Pdf(pdfium::PdfiumError),
Io(std::io::Error),
Json(serde_json::Error),
Image(image::ImageError),
Ocr(String),
Conversion(String),
Config(String),
Other(String),
}

Result of parsing a document.

pub struct ParseResult {
pub pages: Vec<crate::types::ParsedPage>,
pub text: String,
}
NameTypeDocumentation
pagesVec<crate::types::ParsedPage>Parsed pages with projected text layout.
textStringFull document text, concatenated from all pages.

Result of rendering a single page screenshot.

pub struct ScreenshotResult {
pub page_num: u32,
pub width: u32,
pub height: u32,
pub image_bytes: Vec<u8>,
}
NameTypeDocumentation
page_numu32
widthu32
heightu32
image_bytesVec<u8>

Main LiteParse orchestrator.

pub struct LiteParse {
// Some fields omitted
}
  • pub fn new(config: LiteParseConfig) -> Self { /* ... */ }
  • pub fn with_ocr_engine(self: Self, engine: std::sync::Arc<dyn OcrEngine>) -> Self { /* ... */ }

    Override the OCR engine. When set, the engine is used regardless of

  • pub async fn parse(self: &Self, input: &str) -> Result<ParseResult, LiteParseError> { /* ... */ }

    Parse a document from a file path, returning structured results.

  • pub async fn parse_input(self: &Self, input: PdfInput) -> Result<ParseResult, LiteParseError> { /* ... */ }

    Parse a document from either a file path or raw bytes.

  • pub async fn screenshot(self: &Self, input: &str, page_numbers: Option<Vec<u32>>) -> Result<Vec<ScreenshotResult>, LiteParseError> { /* ... */ }

    Generate screenshots of document pages as PNG bytes.

  • pub async fn screenshot_input(self: &Self, input: PdfInput, page_numbers: Option<Vec<u32>>) -> Result<Vec<ScreenshotResult>, LiteParseError> { /* ... */ }

    Generate screenshots from a file path or raw bytes.

  • pub fn config(self: &Self) -> &LiteParseConfig { /* ... */ }

Options for searching text items.

pub struct SearchOptions {
pub phrase: String,
pub case_sensitive: bool,
}
NameTypeDocumentation
phraseString
case_sensitivebool

Search text items for phrase matches, returning synthetic merged items.

Consecutive text items are concatenated and searched. When a phrase spans multiple items, the result is a single merged item with a combined bounding box and the matched text. Font metadata is taken from the first matched item.

pub fn search_items(items: &[crate::types::TextItem], options: &SearchOptions) -> Vec<crate::types::TextItem> { /* ... */ }

Represents a single text item extracted from a PDF page, including its content, position, size, rotation, and font metadata.

pub struct TextItem {
pub text: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub rotation: f32,
pub font_name: Option<String>,
pub font_size: Option<f32>,
pub font_height: Option<f32>,
pub font_ascent: Option<f32>,
pub font_descent: Option<f32>,
pub font_weight: Option<i32>,
pub font_flags: Option<i32>,
pub text_width: Option<f32>,
pub font_is_buggy: bool,
pub mcid: Option<i32>,
pub fill_color: Option<String>,
pub stroke_color: Option<String>,
pub confidence: Option<f32>,
}
NameTypeDocumentation
textString
xf32Viewport-space coordinates (top-left origin, 72 DPI).
yf32
widthf32
heightf32
rotationf32Rotation in degrees (counter-clockwise, adjusted for page rotation).
font_nameOption<String>
font_sizeOption<f32>
font_heightOption<f32>Font size * scale_y from the text matrix — accounts for CTM scaling.
font_ascentOption<f32>
font_descentOption<f32>
font_weightOption<i32>
font_flagsOption<i32>
text_widthOption<f32>Sum of glyph widths (using charcode-based lookup when possible).
font_is_buggyboolWhether the font has buggy encoding (private-use codepoints, TT subset, etc.)
mcidOption<i32>Marked content ID from the PDF structure tree.
fill_colorOption<String>Fill color as ARGB hex string (e.g. “ff000000”).
stroke_colorOption<String>Stroke color as ARGB hex string.
confidenceOption<f32>OCR confidence score (0.0–1.0). None for native PDF text.

Represents a fully parsed page with projected text layout.

pub struct ParsedPage {
pub page_number: usize,
pub page_width: f32,
pub page_height: f32,
pub text: String,
pub text_items: Vec<TextItem>,
}
NameTypeDocumentation
page_numberusize
page_widthf32
page_heightf32
textString
text_itemsVec<TextItem>