pdftract/crates/pdftract-core
jedarden 597f536b19 feat(pdftract-xzfkt): implement caption block classifier
Add Phase 4 caption classification for detecting figure captions.

Implements classify_caption() which identifies blocks as captions when:
- Small font size (median < page body median)
- Follows Figure block within 2 line heights
- Same column as Figure

Module: crates/pdftract-core/src/layout/caption.rs

Acceptance criteria:
- Block immediately below Figure, small font, same column → kind: Caption
- Block 5 lines below Figure → NOT Caption (gap too large)
- Block with body-size font below Figure → NOT Caption (font not smaller)
- Block in different column from Figure → NOT Caption

Tests: 9/9 passed covering all acceptance criteria plus edge cases.

Closes: pdftract-xzfkt

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-24 01:56:34 -04:00
..
benches feat(pdftract-3nwz): add borderless table detection benchmark 2026-05-23 22:30:06 -04:00
build feat(pdftract-43ry): implement predefined CMap registry 2026-05-23 23:00:59 -04:00
examples feat(pdftract-mcp): add MCP server implementation changes 2026-05-23 03:09:56 -04:00
proptest-regressions/parser/lexer feat(pdftract-1jjn): implement PDF numeric literal lexer with full edge case support 2026-05-23 23:17:04 -04:00
src feat(pdftract-xzfkt): implement caption block classifier 2026-05-24 01:56:34 -04:00
tests feat(pdftract-core): add SSRF protection (TH-05) and URL_PRIVATE_NETWORK diagnostic 2026-05-24 01:50:12 -04:00
__test__.pdf feat(pdftract-15pz8): implement multi-process safe cache operations 2026-05-23 05:31:11 -04:00
build.rs feat(pdftract-43ry): implement predefined CMap registry 2026-05-23 23:00:59 -04:00
Cargo.toml feat(pdftract-core): add SSRF protection (TH-05) and URL_PRIVATE_NETWORK diagnostic 2026-05-24 01:50:12 -04:00
pdftract-core.cdx.json feat(pdftract-67tm8): implement MCP stdio transport with integration tests 2026-05-23 00:16:42 -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);