pdfni 0.1.0

Extract tables and Markdown from text-embedded PDFs, with a built-in pure-Rust PDF reader adapted from Mozilla pdf.js.
Documentation

pdfni

A Rust library that extracts tables and Markdown from text-embedded PDFs. To pursue both accuracy and speed, it ships with its own pure-Rust PDF reader adapted from Mozilla pdf.js. Usable as a Rust crate, a CLI, or a WebAssembly module from Node.js and the browser.

Expect breaking changes.

Highlights

  • Table extraction — solid for ruled and text-aligned layouts; support for merged cells is limited (how it works)
  • Markdown extraction from the document model (paragraphs, headings, lists, tables) (pipeline)
  • Built-in pure-Rust PDF reader adapted from pdf.js — no OCR, no page rasterization, no system PDF library (reader lineage)
  • Native, Node.js, and browser via WebAssembly (wasm guide)

What it is not

  • OCR for scanned / image-only PDFs
  • A full PDF renderer (images, annotations, forms, signatures are out of scope)
  • Vertical-writing-aware table detection (the reader can surface vertical text; table detection stays oriented to horizontal layout)

Quick Start

CLI

cargo run --release -- input.pdf output.json

Prints the table Document JSON to output.json. See docs/CLI.md for modes and encrypted PDFs.

Rust

use pdfni::{extract_from_bytes, ExtractOptions};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let bytes = std::fs::read("input.pdf")?;
    let doc = extract_from_bytes(&bytes, None, &ExtractOptions::default())?;
    println!("{}", serde_json::to_string_pretty(&doc)?);
    Ok(())
}

Benchmarks

Full pipeline (table regions are not given), scored with each benchmark's official evaluation tool. Scripts and test data live under bench/ — see each benchmark's README for setup.

Benchmark Task Precision Recall F1
ICDAR 2013 original (eu + us) Region detection (char-level) 0.9347 0.9316 0.9332
ICDAR 2013 original (eu + us) Structure (cell adjacency) 0.9403 0.9335 0.9369
ICDAR 2013 corrected (eu + us) Region detection (char-level) 0.9347 0.9316 0.9332
ICDAR 2013 corrected (eu + us) Structure (cell adjacency) 0.9403 0.9335 0.9369
SciTSR test (3,000 tables) Structure (cell adjacency, macro) 0.9254 0.8997 0.9124

Documentation

License

Licensed under the Apache License, Version 2.0. See LICENSE.

Third-party notices

The bundled PDF reader is adapted from Mozilla pdf.js, and the bundled binary CMap data is derived from Adobe CMap resources. See NOTICE for attribution and license details.