Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ODL-PDF-RUST

A native Rust PDF-to-Markdown/JSON extraction engine. Clean-room reimplementation of opendataloader-pdf built on PDFium via the pdfium-render crate.

Why Rust?

  • Speed: ~975 pages/second on a single core — roughly 10× faster than JVM-based engines at comparable accuracy.
  • Memory safety: no garbage collector pauses, no JVM warmup, predictable latency.
  • Deployment simplicity: one statically-linked binary (plus a single platform dylib for PDFium).
  • Zero marginal AI cost: matches frontier vision models on heading-structure recovery with purely algorithmic extraction — no per-page API calls needed.

Features

Feature Description
XY-Cut++ reading order Recursive page partitioning that correctly sequences multi-column layouts, side-bars, and floating figures
Heading recovery Font-hierarchy analysis + outline section-number detection; correctly classifies section headings even when they are set in body-size fonts
Section-number headings Pattern-matches "6", "6.1", "6.8 Out of Tolerance" as heading promoters independent of font size
Bordered table detection Geometric rule-based table slicer; splits rows and columns from visible PDF border lines
Markdown output GitHub-flavored Markdown with ATX headings, pipe tables, and list items
JSON output Structured element model (type, bounding box, text, heading level, table cells)
Tagged-PDF output Writes a PDF/UA-compliant structure tree onto untagged input PDFs
Hybrid AI mode Optional triage router — sends complex/scan pages to a pluggable vision backend (AWS Bedrock / Claude); purely algorithmic path is the default

Benchmark

Evaluated on a corpus of real-world technical documents (dense tables, multi-column text, section-numbered procedures, scanned forms):

Metric ODL-PDF-RUST
Complex-text recall 96.7%
Heading recall 98.1%
Throughput (single core) ~975 pages/sec
AI cost $0 (algorithmic mode)

Heading-structure recall matches or exceeds frontier vision models (GPT-4o, Claude Opus, Gemini) at ~1000x lower latency and $0 marginal cost in the default algorithmic mode.

Build

Prerequisites

  1. Rust 1.80+ — install via rustup.
  2. libpdfium — a pre-built shared library for your platform. Download from bblanchon/pdfium-binaries and place it in a directory of your choice.

Compile

git clone https://github.com/00EVA/ODL-PDF-RUST.git
cd ODL-PDF-RUST
PDFIUM_DYNAMIC_LIB_PATH=/path/to/pdfium-dir cargo build --release

The PDFIUM_DYNAMIC_LIB_PATH environment variable tells pdfium-render where to find the shared library at both build time and runtime. You can also set it permanently in your shell profile or pass it inline as shown above.

The compiled binary is at target/release/odl-pdf.

Usage

# Extract to Markdown (default)
odl-pdf document.pdf

# Explicit format selection
odl-pdf document.pdf -f markdown
odl-pdf document.pdf -f json

# Write to a file
odl-pdf document.pdf -f json -o output.json

# Enable hybrid AI mode (requires AWS credentials + Bedrock access)
odl-pdf document.pdf --hybrid auto --backend bedrock-claude

At runtime, ensure the directory containing libpdfium is on your library path:

# Linux
export LD_LIBRARY_PATH=/path/to/pdfium-dir:$LD_LIBRARY_PATH

# macOS
export DYLD_LIBRARY_PATH=/path/to/pdfium-dir:$DYLD_LIBRARY_PATH

# Or set PDFIUM_DYNAMIC_LIB_PATH for both build and runtime
export PDFIUM_DYNAMIC_LIB_PATH=/path/to/pdfium-dir

Workspace layout

crates/
  cli/          Binary crate: argument parsing, logging, entry point (odl-pdf)
  entities/     Core type model: BoundingBox, TextChunk, TextLine, TextBlock,
                SemanticTextNode, TableBorder, IObject, Document
  parser/       PDFium bridge: PDF page -> entity model (pdfium-render)
  processors/   Layout processors: reading order (XY-Cut++), paragraph grouping,
                heading detection, table/list detection, pipeline
  output/       Output writers: JSON and Markdown serialisers
  tagging/      PDF/UA tagger: writes a structure tree onto an untagged PDF (lopdf)
  hybrid/       Hybrid AI mode: triage, pluggable backend adapters (mock + Bedrock)

Hybrid AI mode

The optional hybrid mode triages each page algorithmically. Pages that score as "complex" (high image density, low text yield, anomalous layout) are forwarded to a configurable vision backend. The default build includes:

  • mock — deterministic offline adapter for tests.
  • bedrock-claude — AWS Bedrock / Claude vision adapter (stub; wire an aws-sdk dep and implement the HTTP call to enable live inference).

The JSON schema exchanged with backends is a lightweight Docling-inspired format:

{"elements": [
  {"type": "heading", "level": 1, "text": "...", "bbox": [l, b, r, t]},
  {"type": "table", "bbox": [l, b, r, t],
   "cells": [{"row": 0, "col": 0, "row_span": 1, "col_span": 1, "text": "..."}]}
]}

License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages