Skip to content
Code Recycle

Component · for humans & their agents

PDF Reading Order

verified · first-partyactively maintained$0 during beta (was $69)

A two-column PDF sorted by y then x reads across the page, weaving both columns into grammatical-looking English that means nothing. Nothing throws.

by datawright · Code Recycle maintainer

Get it free — beta

Every claim on this page is refundable if it is untrue — refund policy.

Verified: 96 tests · 8/10 mutations caught

Reconstructs a defensible reading order from the text runs a PDF text-extraction library (pdf.js, pdfium, pdf-lib, PDFBox and similar) already produced -- x, y, width, height, text and fontSize -- plus a coordinate origin you declare. This library does not parse PDF files, and it makes no network access, ever.

Reconstructs a defensible reading order from the text runs a PDF text-extraction library (pdf.js, pdfium, pdf-lib, PDFBox and similar) already produced -- x, y, width, height, text and fontSize -- plus a coordinate origin you declare. This library does not parse PDF files, and it makes no network access, ever.

THE SILENT FAILURE. PDF text extraction almost never throws. It returns a string, and the string is wrong in ways that read as merely bad OCR when they are actually structural -- the wrong text goes straight into a search index or an LLM context where nobody reads it closely enough to catch it.

COLUMN INTERLEAVING. A two-column page holds text runs whose y coordinates alternate between the two columns as the extractor walks the page's content stream. Sorting by y then x reads ACROSS the page, weaving the two columns into each other one line at a time. The result is grammatical-looking English that means nothing, and it never throws.

THE Y-AXIS POINTS THE OTHER WAY. PDF user space has its origin at the bottom-left corner with y increasing upward (ISO 32000-1 section 8.3.2.3). Nearly every developer assumes top-left, because that is how screens work. Sorting ascending by y under that wrong assumption returns the page bottom-to-top: a perfectly-ordered, completely reversed document that does not look like a parsing bug unless someone actually reads it start to finish.

ZERO RUNS IS NOT AN EMPTY DOCUMENT. A scanned page has no text layer at all. Extraction returns an empty string, and a pipeline that treats that the same as 'this page has no content' silently converts every page that needs OCR into empty rows, indistinguishable from a page that is genuinely blank. This library returns a distinct empty-page verdict rather than reusing an empty string to mean two different things.

LIGATURES AND HYPHENATION. The letters 'fi' are often extracted as a single glyph, so a search for 'financial' silently fails to match text that visibly contains the word. A word wrapped across a line boundary leaves two fragments that must be rejoined -- but rejoining every hyphen-newline pair also destroys genuine compounds like 'well-being'. Both failure directions are silent; every join this library makes is reported in an audit trail so a caller can revert one it disagrees with.

RUNNING HEADERS AND FOOTERS. The same header or footer repeats on every page and contaminates every extraction with phantom text at every page boundary, indistinguishable from a document title that is actually relevant to the query. Detection only ever reports candidates; removal is a separate, explicit call.

VERIFIED: 96 tests, re-measured by running the suite, 10 deliberate defects applied to the real source, 8 caught and 2 proved to change no observable behaviour (two guards whose conditions are already rejected by the checks after them) — the proofs ship in mutations.json after closing two gaps a first pass missed: an object nested inside a frozen wrapper that was never itself frozen, and a per-column line-index offset silently dropped when dehyphenation reports were combined across columns.

DELIVERY: signed download of a hash-verified tarball, immediately on purchase. Permissive licence: unlimited products, unlimited clients, unlimited seats, no attribution, perpetual and irrevocable. One restriction, do not republish the source as source.

Interface

What you call, and what comes back. Types and signatures only — the implementation ships with the source.

  export function detectColumns( runs: TextRun[], options?: ColumnDetectionOptions, ): ColumnDetectionResult;
  export function classifyRunColumn( run: TextRun, columns: ColumnBand[], spanOverlapThreshold = DEFAULTS.spanOverlapThreshold, ): ColumnClassification;
  export function detectRunningHeadersFooters( pages: PageRuns[], origin: CoordinateOrigin, options?: HeaderFooterOptions, ): HeaderFooterCandidate[];
  export function removeHeaderFooterRuns( pages: PageRuns[], origin: CoordinateOrigin, candidates: HeaderFooterCandidate[], options?: HeaderFooterOptions, ): PageRuns[];
  export function dehyphenate( lines: string[], options?: DehyphenationOptions, ):;
  export function normalizeLigatures(text: string):;
  export function containsLigature(text: string): boolean;
  export function reconstructPage( runs: TextRun[], origin: CoordinateOrigin, options?: ReadingOrderOptions, ): ReadingOrderResult;
  export type ColumnClassification = | { spanning: false;
  export type CoordinateOrigin = "bottom-left" | "top-left";
  export type ReadingOrderVerdict = "ok" | "empty-page";

01Capabilities

Does

  • + Structured document extraction

Doesn’t

  • No exclusions declared

02Requirements & stack

Depends on

No declared dependencies

Credentials needed

None declared

Stack

typescript

03Community

No endorsements yet

No verified confirmations yet — be the first.

Confirmations come from verified purchasers, installers, vetted reviewers, or an installation outcome your org reported through the agent tools. They grade quality — security is verified separately, and community votes can never override the security gate.

Open an issue

Sign in to confirm — weight comes from verified usage, not vote count.

0 open · 0 answered · 0 fixed · 1 said it worked

04Trust Passport

Full passport →
–/100

0/0 automated components pass. An automated score is never a security guarantee.

✓ Verified · first-partyreviewed Sep 20, 2026 · re-verification due Dec 19, 2026
  • publisher identity Publisher status verified; 1 verification(s) on file
  • malicious pattern scan No known malicious-behavior patterns across 23 source file(s) plus listing text
  • capability contract All 0 observed capability reference(s) match the declared manifest
  • agent safety scan No injection patterns in agent-readable content
  • provenance No release signature or provenance attestation
  • behavioral sandbox Not performed in this environment — requires the production isolated runner (docs/sandbox-requirements.md). No untrusted code is ever executed on the application host.

Every listing must pass this review before it can be sold, and it is re-run on every release. Verification describes what we checked — it is not a guarantee that the software is safe.

VersionChannelReleasedNotes
1.0.0stableAug 5, 2026First public release.