Pdf Processor
Eight Architectural Moves That Fill the Empty Quadrant of Frontend PDF Extraction
TLDR
Building a high-fidelity PDF extraction engine that runs entirely in the browser without server dependencies or ML model weights requires combining eight foundational architectural moves. Combining vector CTM baking, region-typed classification, underline filtering, topological cell merging, nearest-cell snapping, Web Worker isolation, per-page message streaming, and visual grid mapping fills the deterministic-structural-frontend niche.| Architectural Move | Technical Responsibility | Primary Engineering Benefit |
|---|---|---|
| 1. CTM-Baked Vectors | Reconstruct vector path primitives | Reads table borders before text processing |
| 2. Region-Typed Classification | Pre-assign text to single region | Zero text item leakage by construction |
| 3. Underline Discrimination | Filter baseline-adjacent H-lines | Eliminates 99% of phantom 1x1 tables |
| 4. Topological Cell Merge | Query vertical line continuity | Eliminates fragile whitespace merge guesses |
| 5. Nearest-Cell Snap | Euclidean cell center snapping | Eliminates coordinate jitter data drops |
| 6. Web Worker Isolation | Off-thread pipeline execution | Main thread UI stays 100% responsive |
| 7. Per-Page Streaming | Stream per-page worker messages | Prevents structured clone postMessage crashes |
| 8. Visual Grid Mapping | Export Cartesian cell arrays | Enables instant matrix table editing |
The eight foundational architectural moves
[PDF Stream] ---> [1. CTM Vectors] ---> [3. Underline Filter] ---> [2. Region Scoper]
|
[Visual Grid Mapper] <--- [8. Grid Map] <--- [5. Nearest Snap] <--- [4. Topo Merge]
1. CTM-Baked vector segments
Walk the PDF page operator list (OPS.constructPath, OPS.transform), transforming path vertices through the Current Transformation Matrix (CTM) to extract normalized vector line segments in viewport screen coordinates.
2. Region-Typed classification
Enforce a structural invariant: every text item belongs to exactly one region. Mark claimed text in anassignedTextIndices bitset during table, heading, and list extraction passes.
3. Underline-vs-Border discrimination
Filter horizontal line segments that sit $0\text{ to }5\text{px}$ below text baselines before running lattice table reconstruction.// Remove decorative underlines from table border candidate pool
if (yDist >= -1 && yDist <= 5 && isXSpanOverlapping(textItem, lineSegment)) {
underlineSegmentSet.add(lineSegment.id);
}
4. Topological cell-merge inference
Determine table cell merging by checking vertical line segment presence across row coordinates rather than measuring visual text spacing.5. Nearest-Cell Euclidean snapping
Snap scoped text items to cell centers within a $15\text{px}$ Euclidean radius, accommodating PDF coordinate jitter.6. Web worker isolation
Execute PDF parsing, vector reconciliation, layout classification, and HTML assembly inside a dedicated Web Worker thread.7. Per-Page message streaming
Stream incremental per-page result objects (type: 'page') from the Web Worker to prevent memory crashes on large documents.
8. Visual grid mapping integration
Map extracted HTML tables directly intoVisualGridMapper Cartesian matrices for downstream web editor manipulation.
Rule of thumb: Combine vector operator parsing, single-region text scoping, and off-thread Web Worker execution to build deterministic browser PDF engines.
Read this post in the full Engineering Journal →