Repository navigation
PDF pages are read as laid out: tables, headings, columns and page furniture - #292
Merged
Merged
Conversation
…rniture Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…l text, bounded reading Furniture is decided once tables are found and needs a letter; a table is carried over consecutive pages; a cell is typed only when its value reads back as shown; a page past 5,000 lines or whose layout fails is read as its text layer; outline placement is linear and shifted on every page; a font's widths, the gutter's slots and the grid search are bounded; turned text keeps its lines; furniture is named by shape. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…furniture kept out of tables An entry after a whole-paragraph title is searched past its lines; a run drawn twice at one place (either direction) is read once and counted by the guard; a furniture candidate never joins a borderless table and is counted per page; a borderless run holds at most 200 lines and a grid checks only the lines within its height. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…xt repeated in another font is text A furniture candidate at a borderless run's end stays a row unless it sits apart from the run; a repeat of the same text at one place counts as a copy only in the same font. The bounded-work tests count work instead of timing it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…w only when it reads as one It stays when it fills every column (the table's repeated header) or opens a row at the table's row spacing; a running header or a page number near the table is furniture. The bands come from the table's other lines. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…r alone is never its row Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…number is never a table row Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
dp-pdf-layout
branch
from
November 6, 2026 17:42
3b25c1c to
eba1390
Compare
This was referenced Nov 6, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #289
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
The reference extractor reads a PDF as it is laid out: its tables become typed tables and datasets with rows cited by page, headings come from the type when the file has no outline, two-column pages read in order, sideways pages read like any other, and running headers, footers and page numbers are left out of the text and listed.
Why
A PDF was read as its text layer only. A table came out as loose words with nothing to say which cell was which, so it could not become a dataset and a hit on a row did not carry its header; a PDF with no outline (most exported docs and decks) had no headings, so its chunks had no section path; and running headers and page numbers were indexed on every page. On the document-parsing bench (#289) the previous extractor scored 0 on PDF table cells and 0.15 on PDF headings on the held-out split.
Design
extractor/loom_extractor/pdflayout.pyreads a page from the positions pypdf reports for each run of text it shows (extract_text(visitor_text=...), its public interface) and the lines the page draws (its own walk of the content stream and form XObjects). No new dependency./Widths, a CID font's/Wthrough its ToUnicode map (inverted), or Adobe's metrics for the standard fonts. pypdf reports each piece of one text operator at the operator's start, so a piece with the same matrices as the one before goes on from its end (a ligature drawn from a second font no longer lands at the line's start)./Rotateor turned content reads like any page; the rest is kept as paragraphs after it.attrs.furniture), paragraphs, lists, code and headings, asdocs/architecture/document-extraction.mdlists; a table that goes on over consecutive pages in the same columns is one table, its repeated header read once; an outline, when there is one, names the headings, under any heading set larger than all of them, on every page.tabular.tablelike a sheet's: a typed table inartifact.tablesand row blocks ofcolumn: valuelines, cited by pages and rows, soknowledge.ingestmakes each a dataset. A cell is typed only when its value reads back as shown (1.50and a version1.10stay text).Alternatives: pypdf's layout mode prints a fixed-width page, which keeps alignment but loses cells that wrap and gives no fonts; its internals are a private module. A model-based layout reader is out of scope for the reference extractor (size, speed, determinism).
Scope and risk
extractor/loom_extractor/(the PDF parser,PARSER_VERSION2, andcsvfile._cellmade public astyped_cell), docs, tests. A PDF ingested again makes a new artifact with a different shape: furniture lines are no longer blocks, table text is row blocks instead of flattened lines, list items and code arelistandcodeblocks. Text is kept by the guard. Bounded on hostile input: a page's lines (5,000), drawing operators (400,000; past it no rules) and rules (4,000; past it no ruled tables, the grid search by sorted position), ToUnicode maps and width arrays (1 MiB, 65,536 values written), the gutter's slots (a few thousand however wide the page), form depth 4; a long line and a long outline are read in linear time.Compatibility, rollout and rollback
tables, andattrs.furnitureandattrs.orientation(on a block of turned text). A build N-1 server reads N's artifacts (unknown attrs are kept as attrs; tables were already in the contract).Tests
tests/unit/test_document_extraction_pdf_layout.py(PDFs built byte by byte): a table over three pages is one table and rows at the page margins stay rows; text drawn turned without/Rotate; outline headings under a larger title on a page read as its text layer too; a CID font's widths through its map; widths, a very wide page and a 3,000-entry outline in bounded time; a ruled table is a typed table with rows cited by page and section and passesparse_artifact; aligned columns without rules are a table and a wrapped cell stays one cell; a table over two pages is one table with its header read once; headings from size and weight, numbering ranking one style, a bold sentence not a heading; two columns read left then right; page furniture left out and named; a page shown turned is read in its text's direction; a list marker is not a column; the text-layer guard; a page past the rule bound; ToUnicode ranges and arrays. The existing PDF tests pass with the outline placed on a line inside a paragraph.Document-parsing bench, held-out split (
python -m bench.docparse run --out new.jsonlon each build, thenscore previous=... new=... --split heldout), paired difference with a 95% bootstrap interval:Heading level accuracy 0.33 → 1.00; silent loss unchanged (2, both text inside a picture on a slide, which needs OCR); scanned pages still fail as needing OCR. The dev split moved the same way (tables 0 → 0.888, headings 0.165 → 0.905). Time 0.07 → 0.18 s and peak memory 36 → 37 MB a file.
Fifteen real PDFs the corpus does not hold (three RFCs, twelve public conference decks, 11 to 194 pages): no failure, every page read as laid out (no guard fallback), every letter and digit of the text layer kept, 0.06 to 13.6 s a file (the 194-page RFC), at most 80 MB.
AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. I checked each rule against failing bench files on the dev split only, the guard against fifteen real PDFs, and the bounds against hostile inputs in the tests.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code