GitHub
PDF statement extraction (research notes)

Extracting tables from PDF statements (deferred research notes)

PDF import was cut from WP-11 on purpose (plans/11-enhanced-import.md). This document records the survey so whoever picks it up does not repeat it. Everything here was measured in August 2026. The versions, closure sizes and capability claims were compiled and run, not read off a README. Re-check the version numbers before relying on them. The conclusions are less likely to change than the releases.

PDF import is feasible in pure Rust, and the extractor is not the hard part. Getting positioned glyphs out of a PDF took about 60 lines. Most of the work is turning positioned glyphs into correct rows across wrapped descriptions, page breaks and right-aligned amount columns.

Why it was deferred

Bank PDF layouts vary far more than OFX or CSV do, and a wrong extraction in a bookkeeping app is worse than no extraction. The other formats in WP-11 have a correct answer we can validate. A PDF gives a plausible answer that needs a human to check every row. That needs a different UX and a different amount of work, and adding it to the same milestone risked delaying the rest of WP-11.

Recommendation

Use pdf-extract (0.12.0, MIT, active, ~595★). It is often said that no pure Rust crate exposes glyph positions, but this one does, through the public OutputDev trait:

fn output_character(&mut self, trm: &Transform, width: f64, spacing: f64,
                    font_size: f64, char: &str);
fn begin_word(&mut self);  fn end_word(&mut self);
fn begin_page(&mut self, page_num: u32, media_box: &MediaBox, art_box: Option<...>);
fn stroke(&mut self, ctm: &Transform, colorspace: &ColorSpace, style: &..., path: &Path);
fn fill(&mut self, ...);

trm.m31 / trm.m32 are the glyph’s x and y. begin_word/end_word give you word segmentation. stroke/fill with a Path give you the ruling lines, so both stream-mode (whitespace-based) and lattice-mode (line-based) table detection are available without leaving Rust.

A working probe against a text-layer bank statement produced:

positioned WORDS: 31   ruling-line subpaths: 0
["Date", "Description", "Debit", "Credit", "Balance"]
["01/02/2026", "COFFEE ROASTERS #114",  "4.50",         "1,995.50"]
["01/03/2026", "ACME HARDWARE & SUPPLY","128.99",       "1,866.51"]

Two problems the probe ran into

  1. Partition by page in begin_page. Otherwise every page collapses into one coordinate space and rows from page 2 interleave with page 1 at the same y.
  2. Naive left-edge clustering fails on right-aligned amount columns. The first pass put 3,200.00 in Debit instead of Credit, because both columns’ left edges vary with the number’s width. The fix is to seed column boundaries from the header row, then locate numeric cells by their right edge and non-numeric cells by their left. That took the probe from 6/7 to 7/7 rows minus one text-overrun case.

Known risks in pdf-extract

The alternative, if you want to defer again

Use pdftotext -tsv from poppler-utils. Note that this is -tsv, not -layout. It emits Tesseract-style TSV with per-word left/top/width/height, which the csv crate reads directly with .delimiter(b'\t'). -layout looks good on clean files but puts amounts at inconsistent character offsets on real ones, so do not build on it.

The poppler-utils closure measured 154.9 MiB across 55 store paths, reducible to roughly 100 MiB with poppler_min.override { utils = true; }. It is GPL-2+, which is defensible as a separate process and not as a linked library. That is a big dependency for a project that ships as a single binary, which is the other reason to prefer pdf-extract.

Ruled out, with reasons

OptionWhy not
pdfium-render (0.9.3, MIT/Apache)Works, but nixpkgs pdfium-binaries ships only lib/libpdfium.dylib, with no static .a. You would ship and codesign a dylib, which breaks the single-binary property. The closure is otherwise small (6.8 MiB, 1 path, no deps). Keep as the fallback if pure Rust stalls.
mupdf-rs (0.8.0)It is AGPL-3.0, and Artifex enforces its licences in court. The licence alone rules it out.
poppler-rs (0.26.0)Doesn’t bind poppler_page_get_text_layout(), so it cannot give you per-character rectangles, which is the one thing you need.
pdf / pdf-rs (0.10.0)It exposes raw content-stream operators only, so you would reimplement text-state tracking yourself. Sporadic maintenance (a two-year gap between 0.9.0 and 0.9.1).
lopdf (0.44.0)It is very active, but it is a document-structure library with no text positioning. It is already a transitive dependency of pdf-extract.
tabula-javaIt needs a JVM, with a ~887 MiB closure.
Python camelot / pdfplumberIt needs Python and Ghostscript (AGPL), with a ~1.14 GiB closure.

No mature Rust table-detection crate exists. Of ~50 reverse-dependencies of pdf-extract, none add table extraction. You write this part yourself either way. That is the main argument for staying in Rust, since a 155 MiB dependency would still leave you writing the column logic.

If you build it

When this survey was written, QuickBooks was also deferred, and that reasoning still explains its design. A QuickBooks export is not a bank statement. It already carries both sides of every transaction, in QuickBooks’ own chart of accounts, so going through a rules file would mean flattening two-sided data into one-sided rows and then guessing the other side back.

It has since shipped as its own pipeline (WP-17, plans/17-quickbooks-journal-import.md) for the QuickBooks Online Journal report. It has no intermediate CSV and no hledger import. The account mapping is stored as plain hledger alias directives in the journal rather than in a separate store, and the file goes in through the same New Transactions drop target. See Importing from QuickBooks for the user side and the internals for the parser. .qbo files are OFX and go through the ordinary OFX path.