Engineering Journal
Pdf Processor
Pdf Processor

Your extractor should never merge text it can link instead

2026-07-04

TLDR

Concatenating fragmented PDF text items during extraction permanently destroys spatial coordinate truth in favor of linear text streams. If continuation detection heuristics guess wrong, merged headings or columns become permanently corrupted. Preserving spatial fragments and linking them via HTML data attributes (data-flow-next, data-flow-prev) allows different downstream consumers (responsive web viewports, linear text exporters, design-faithful visual canvas editors) to materialize their required view dynamically.
Architecture ModelSpatial Coordinate TruthResponsive Web ReflowDestructive Corruption Risk
Linear String ConcatenationDestroyed at extractionRigid / Non-responsiveHigh (Heuristic merge errors permanent)
Relationship Linking (data-flow)Preserved on DOM nodes100% ReflowableZero (Edges removable downstream)

Architectural implementation: linked attribute streams

Annotate spatial text nodes with relationship links rather than performing string concatenation:

<!-- Preserved spatial HTML fragments with dynamic continuation linking -->
<div id="frag-7" class="pdf-region" data-flow-next="frag-8">
  The day is
</div>
<div id="frag-8" class="pdf-region" data-flow-prev="frag-7" data-continuation="true">
  brighter.
</div>
// Linear Text Exporter: Walks linked continuation chains dynamically
export function exportLinearTextChain(rootElement) {
  const regions = Array.from(rootElement.querySelectorAll('[data-flow-next]'));
  let fullText = '';

for (const node of regions) { fullText += node.textContent.trim() + ' '; }

return fullText.trim(); }

Rule of thumb: Annotate spatial text fragments with relationship links (data-flow-next) rather than executing destructive string concatenation at extraction time.
Read this post in the full Engineering Journal →