pdftract/crates/pdftract-core
jedarden 13e815e40c feat(pdftract-6bxw): implement object stream (ObjStm) parser
Implement the parser for PDF 1.5+ object streams with:
- Decompression via Phase 1.5 stream decoder
- Arc<RwLock<HashMap>> caching for thread-safe access
- /Extends chain support with cycle detection
- Depth limit (MAX_EXTENDS_DEPTH = 16) for adversarial protection
- get_object() API for xref type-2 entry resolution

Acceptance criteria verified:
- Critical test: N=10 objects all dereference correctly
- /Extends chain: both ObjStms' objects dereference correctly
- Cyclic /Extends: emits STRUCT_CIRCULAR_REF
- Truncated ObjStm: partial objects + diagnostic
- Decompression bomb: emits STREAM_BOMB
- Cache hit: returns cached Arc (Arc::ptr_eq verified)

Unit tests: 12 tests covering all acceptance criteria and edge cases.

Refs: pdftract-6bxw, plan Phase 1.2 line 1072
2026-05-20 19:03:53 -04:00
..
examples docs(pdftract-49f8): establish Cargo.lock policy and documentation 2026-05-20 18:13:14 -04:00
proptest-regressions/parser/lexer feat(pdftract-59zz): implement MCP bearer token ingress channels and TH-03 enforcement 2026-05-18 02:47:54 -04:00
src feat(pdftract-6bxw): implement object stream (ObjStm) parser 2026-05-20 19:03:53 -04:00
tests feat(pdftract-5omc): implement SDK conformance test runner pattern 2026-05-18 01:22:23 -04:00
Cargo.toml docs(pdftract-49f8): establish Cargo.lock policy and documentation 2026-05-20 18:13:14 -04:00
README.md docs(pdftract-49f8): establish Cargo.lock policy and documentation 2026-05-20 18:13:14 -04:00

pdftract-core

The core Rust library for PDF text extraction. This crate provides the parsing, layout analysis, font encoding recovery, and text extraction primitives used by the CLI (pdftract-cli) and Python bindings (pdftract-py).

Cargo.lock Policy

This workspace checks in Cargo.lock at the repository root. This is unconventional for library crates—the Cargo Book historically suggested that only binary crates should check in lockfiles, allowing library consumers to resolve their own dependency versions.

pdftract departs from this convention for release reproducibility:

  1. SLSA Level 3 provenance requires that every milestone tag produces byte-identical artifacts across builds. Without a checked-in lockfile, two runs of cargo build on the same commit can resolve different transitive dependency versions, producing different binary hashes.

  2. Multi-output artifacts—this workspace produces Rust crates (pdftract-core, pdftract-cli), Python wheels (pdftract-py), and Docker images. All must be built from the same dependency tree.

  3. Supply-chain security—the lockfile pins checksums for all transitive dependencies, enabling cargo audit to detect yanked or compromised crates.

  4. Downstream consumers can still ignore the lockfile if needed. Cargo allows cargo build --frozen with a local lockfile override, or consumers can vendor the crate with their own dependency resolution.

The tradeoff—occasional merge conflicts when PRs update overlapping dependencies—is worth the guarantee of reproducible releases. See CONTRIBUTING.md for the lockfile-update workflow.

Modules

  • parser: PDF spec parsing (xref, trailer, object streams, indirect references)
  • font: Font encoding recovery, glyph name lookup, fingerprinting
  • layout: Page layout analysis, region segmentation, reading order
  • extract: Text extraction with provenance (bounding boxes, confidence scores)
  • ocr: Tesseract integration for raster pages

Usage

use pdftract_core::{extract_text, ExtractOptions};

let options = ExtractOptions::default();
let result = extract_text("document.pdf", &options)?;
println!("{}", result.text);