Repository navigation
PDF Internals and Extraction
SIDHARTH SINGH edited this page Dec 3, 2026
·
1 revision
Everything inside src/pdf/, src/optimize/, src/merge/, src/inspect/, and src/extract/ executes natively in TypeScript without external PDF binaries.
-
Parser (
src/pdf/parser.ts): Handles broken/Lengthnumbers viaendstreamscans, trims stray trailing bytes on deflate decompression, resolves PNG row predictors, chases classic and cross-reference stream/Prevchains cleanly, locates incremental updates in the final 4,096 bytes, and falls back torecoverByScan()when xref tables are corrupted. -
Optimizer (
src/optimize/): Runs four progressive compaction tiers (none,fast,balanced,maximum). Atbalanced(default), reachability GC, semantic SHA-256 stream deduplication (decoded bytes + metadata excluding/Lengthand/Filter), 3-pass object deduplication, object stream packing (ObjStm), and empirical dual-layout comparison shrink Chromium output typically by 17–21% while keeping every text span searchable.
-
Text & Coordinate Runs (
extractText(),extractPositionedText()): Tracks graphics CTM stacks and font matrices, recursing into Form XObjects up to depth 8, resolving/ActualTexttags (preserving emoji sequences cleanly), and auto-scoring 1-byte vs 2-byte CID mappings. -
Tables & Indian GST Invoices (
extractTables(),extractInvoiceData(),isValidGstin()): Clusters aligned columns using negativeTJkerning splits without breaking blank middle cells, merges multi-page tables by deduplicating repeating column headers, parses INR totals cleanly without confusing Sub Totals with Grand Totals, and runs the Mod-36 Luhn checksum on 15-character GSTINs. -
Scan Quality (
inspectScanQuality()): Classifies uploads as'searchable','scanned','hybrid', or'empty', flags estimated DPI under 150 DPI, highlights oversized image streams, and checks the common< 200 KBGovTech portal cap.
- Home
- Architecture & Render Pipeline
- PDF Internals & Extraction
- Unicode 16, Fonts & Legacy Indic
- Security & SSRF Model
- Digital Signing (
signPdf) - True Redaction (
redactPdf) - Semantic Diff & Redlines (
diffPdfs) - Self-Auditing Renders (
renderVerified) - PDF/A-3b & E-Invoices (
renderEInvoice) - HTTP, MCP, CLI & Puppeteer
Handbook & Deep Analysis: bahubalisid.github.io/onex