Document AI & ParsingFact-Checked & Verified

PDF to JSON Extraction: Spatial Coordinates, Bounding Boxes & Document Parsing Architecture

BT
BrivTools Data Engineering Team
12 min read
PDF to JSON extraction architecture: spatial coordinates x y width height, bounding box reconstruction, and RFC 8259 document schema parsing
Why Plain Text Extraction Breaks Structured PDF Layouts

Standardized under ISO 32000, the Portable Document Format (PDF) was engineered as a digital printing canvas rather than a semantic data structure. Inside a PDF stream, text does not exist as flowing paragraphs or tabular matrices; instead, it is stored as isolated, coordinate-positioned glyph instructions. When standard command-line tools or basic scripts extract raw text, they discard 2D coordinates—flattening multi-column financial statements and itemized invoices into scrambled strings.

Spatial Continuity:Preserving x, y, width, and height attributes allows data engines to mathematically reconstruct rows, columns, and data key-value pairs.
Client-Side Privacy:Running WebAssembly-powered parsers directly inside local browser RAM guarantees that financial PII never leaves the user device.

1. Inside ISO 32000: Digitally Born Character Streams vs. Scanned Raster PDFs

Before designing an automated document ingestion pipeline, developers must distinguish between the two fundamental types of PDF files encountered in production:

Digitally Born Vector PDFs

Generated programmatically by ERP software, billing engines, or headless browser rendering. These contain embedded font dictionaries, glyph mappings, and vector drawing operators. Character stream parsing extracts high-precision text and bounding boxes deterministically.

Scanned Raster Image PDFs

Created by physical office scanners or smartphone photography. The document contains only compressed pixel bitmaps (/DCTDecode or /CCITTFaxDecode). Extracting text requires Optical Character Recognition (OCR) rather than character stream parsing.

2. Font Encodings, Unicode Mappings & Ligature Decoding

Even digitally born PDFs can emit garbled text if the parser fails to interpret embedded /ToUnicode mapping CMaps. PDFs frequently use custom subset fonts where glyph index 0x01 represents the letter "e".

Furthermore, professional typographic documents replace letter pairs like fi, fl, and ffi with unified typographic ligatures. Robust extraction engines map these composite glyphs back to standard UTF-8 characters ("fi" → "f" + "i") so downstream search engines and database queries match expected strings.

3. Anatomy of a Coordinate-Aware PDF to JSON Schema (RFC 8259)

Rather than outputting an unstructured array of strings, a production-grade schema structures document data into metadata, page viewports, and bounded text fragments. The BrivTools PDF to JSON Converter produces compliant RFC 8259 output ready for database ingestion:

Production PDF to JSON Output Schema
{
  "metadata": {
    "fileName": "enterprise-invoice-q3.pdf",
    "fileSizeBytes": 148920,
    "mimeType": "application/pdf",
    "pageCount": 1,
    "documentInfo": {
      "title": "Invoice #INV-2026-089",
      "producer": "BillingEngine v4.2"
    }
  },
  "pages": [
    {
      "pageNumber": 1,
      "viewport": { "width": 612, "height": 792 },
      "textItems": [
        { "text": "Item Description", "x": 54.0, "y": 620.5, "width": 88.4, "height": 11.0, "fontSize": 11.0 },
        { "text": "Qty", "x": 380.0, "y": 620.5, "width": 19.2, "height": 11.0, "fontSize": 11.0 },
        { "text": "Line Total", "x": 495.0, "y": 620.5, "width": 52.1, "height": 11.0, "fontSize": 11.0 },
        { "text": "Dedicated Cloud Cluster", "x": 54.0, "y": 598.0, "width": 112.6, "height": 10.0, "fontSize": 10.0 },
        { "text": "2", "x": 380.0, "y": 598.0, "width": 6.1, "height": 10.0, "fontSize": 10.0 },
        { "text": "$2,400.00", "x": 495.0, "y": 598.0, "width": 48.3, "height": 10.0, "fontSize": 10.0 }
      ]
    }
  ]
}

4. Reconstructing Multi-Column Tables from Spatial Bounding Boxes

With individual bounding boxes captured, reconstructing table rows becomes a deterministic clustering problem. Because typographical baselines can drift slightly, items with matching y coordinates within a small vertical tolerance (±2 points) belong to the same row:

The Row-Clustering Algorithm
  1. Group by Y-Tolerance: Cluster fragments whose vertical positions fall within |y1 - y2| ≤ 2.0 pt into unified table rows.
  2. Sort Horizontally: Order all elements within a clustered row by their x coordinate from left to right.
  3. Assign Column Buckets: Match x positions against header coordinates to map each cell to its column header ("Qty", "Line Total").

5. Choosing the Right Output: PDF to JSON vs. Markdown vs. Plain Text

Selecting the right extraction format depends entirely on your downstream processing architecture:

Extraction TargetPrimary Use CaseSpatial Data PreservedIdeal Processing Engine
PDF to JSONETL jobs, invoices, database JSONB storageYes (x, y, w, h, font size)PostgreSQL, Python, Node.js ETL
PDF to MarkdownLLM embeddings, RAG ingestion pipelinesSemantic (#, ##, pipe tables)Vector DBs, LangChain, LlamaIndex
PDF Plain TextFull-text search indexing, word countsNone (linear stream)Elasticsearch, Grep, Word Count

For RAG vector pipelines requiring header chunking, explore our companion specification on PDF to Markdown for LLM RAG pipelines or use our raw PDF Text Extractor.

6. Frequently Asked Questions

How does PDF to JSON preserve table columns and spatial layouts?+
Direct Answer Summary:By attaching exact geometric bounding boxes (x, y, width, height) to every parsed text run rather than flattening them into linear prose.

Standard text extractors discard the PDF coordinate matrix, reading characters in stream order. Because PDFs store text as positioned glyph commands rather than reading paragraphs, multi-column tables become jumbled strings. An RFC 8259 JSON schema records typographical points (where 1 pt = 1/72 inch) for each word, allowing post-processors to sort tokens into horizontal rows and vertical columns with strict mathematical tolerance.

Why does PDF text extraction return empty text on scanned documents?+
Direct Answer Summary:Scanned PDFs contain embedded raster images of paper pages with no underlying glyph character stream.

Unless a scanned document has undergone Optical Character Recognition (OCR) to inject an invisible 'hidden text layer', the PDF file contains only binary bitmap streams (DCTDecode JPEG or CCITTFaxDecode). PDF-to-JSON parsers inspect vector character operations; if no font glyph mappings exist in the page dictionary, the text payload is empty.

What is the key difference between PDF to JSON and PDF to Markdown?+
Direct Answer Summary:JSON delivers raw spatial coordinates and structural arrays for database storage, whereas Markdown produces human-readable headings and tables for LLM prompt context.

PDF to JSON is engineered for programmatic ETL pipelines, PostgreSQL JSONB storage, and deterministic data extraction from forms and invoices. PDF to Markdown translates visual layout into semantic hierarchy (#, ##, pipe tables) optimized for LLM token limits and Retrieval-Augmented Generation (RAG).

Can password-protected PDFs be converted to JSON in the browser?+
Direct Answer Summary:Only if the document owner permits extraction, or if the user provides the decryption key in memory.

PDF security defines two password types: User Passwords (which prevent opening the document) and Owner Passwords (which restrict permissions like printing or text extraction). Modern client-side WebAssembly tools can decrypt files locally in browser RAM once the appropriate credential is provided.

Client-Side WebAssembly Utility

Convert PDF Documents to Structured JSON Instantly

Extract coordinate-aware text items, bounding boxes, font sizes, and document metadata locally inside your browser with zero server uploads.

Profit Margin Toggles
S-Curve Ramp Delays
100% Client-Side Privacy
Open Free PDF to JSON ToolNo signup required • Instant calculations