code wiki / (root) / nx_lib_pdf.nx

nx_lib_pdf.nx source

↩ module page · 34 lines · 1581 B

1// nx_lib_pdf.nx -- sovereign PDF -> text for the library (retires docling). 2// WIRES the ecosystem's nx_pdf_text (objects -> FlateDecode -> per-font CMap -> 3// content-stream Tj/TJ -> UTF-8) + nx_lib_fetch. PROVEN LIVE: fetched the 2.2MB 4// arXiv:1706.03762 PDF over sovereign TLS-1.3 and extracted 536KB of correct 5// text ("1 Introduction Recurrent neural networks ...") -- no poppler/pdfminer/ 6// docling, no python. license_tier: ORIGINAL 7// genealogy_id: nishi_library_sovereign_pdf_2026_07_01 8import "nx_lib_fetch.nx" 9import "nx_pdf_text.nx" 10const K_MAGIC_16777216: i64 = 16777216 11 12// extract UTF-8 text from PDF bytes already in memory. returns text length. 13func nx_lib_pdf_text(pdf: *u8, pdflen: i64, out: *u8, out_cap: i64) -> i64 { 14 return nx_pdf_extract_text(pdf, pdflen, out, out_cap) 15} 16 17// fetch a PDF url over sovereign TLS-1.3, strip HTTP headers, extract its text. 18// returns text length, or a negative fetch error. 19func nx_lib_pdf_fetch_text(store: *TrustStore, url: *u8, out: *u8, out_cap: i64) -> i64 { 20 let cap: i64 = K_MAGIC_16777216 21 let buf: *u8 = sys_mmap(cap) 22 let gc: i64 = nx_lib_fetch(store, url, buf, cap) 23 if gc < 0 { return gc } 24 var bs: i64 = 0 - 1 25 var bi: i64 = 0 26 while bi + 3 < gc { 27 if bs < 0 { if buf[bi] == 13 as u8 { if buf[bi+1] == 10 as u8 { if buf[bi+2] == 13 as u8 { if buf[bi+3] == 10 as u8 { bs = bi + 4 } } } } } 28 bi = bi + 1 29 } 30 var bp: *u8 = buf 31 var bl: i64 = gc 32 if bs >= 0 { bp = ((buf as i64) + bs) as *u8; bl = gc - bs } 33 return nx_pdf_extract_text(bp, bl, out, out_cap) 34}