Browser Usage (WASM)
Run LiteParse entirely in the browser with the WASM package.
LiteParse ships a WebAssembly package that runs entirely in the browser. It supports PDF parsing, LiteParse’s own OCR models (ocria-nano), and custom OCR engines implemented in JavaScript.
Install
Section titled “Install”npm install @llamaindex/liteparse-wasmQuick start
Section titled “Quick start”import init, { LiteParse } from "@llamaindex/liteparse-wasm";
// Load the WASM moduleawait init();
const parser = new LiteParse({ ocrEnabled: false, outputFormat: "json",});
// data is a Uint8Array (e.g. from <input type="file"> or fetch)const bytes = new Uint8Array(await file.arrayBuffer());const result = await parser.parse(bytes);
console.log(result.text);console.log(result.pages[0]);What works in the browser
Section titled “What works in the browser”- PDF parsing from
Uint8Arrayinput (usefile.arrayBuffer()to get bytes from a file picker for example) - Built-in OCR with ocria-nano: LiteParse’s own models, including LayoutNet for tables and layout (see below)
- Custom OCR via the
ocrEnginecallback interface (see below) - Text, JSON, and markdown output formats
- Document complexity via
parser.isComplex(bytes)— see the complexity guide - The extraction options — annotations, form fields, structure trees, vector graphics, and the rest. See Extraction options
What doesn’t work
Section titled “What doesn’t work”- File path input — pass
Uint8Arrayinstead - DOCX/XLSX/PPTX conversion — requires LibreOffice, which isn’t available in the browser
- Built-in Tesseract or HTTP OCR — use ocria-nano or the custom
ocrEngineinterface instead - Screenshots — not available in the WASM build
imageOutputDir— there is no filesystem to write to. UseextractImagesand read the bytes from the result instead
OCR with ocria-nano
Section titled “OCR with ocria-nano”The WASM build runs ocria-nano, the same OCR and table models as the native CLI, inside WebAssembly (no server, no ONNX Runtime). The models are downloaded on first use: load them once and share the handle across parsers.
import init, { LiteParse, OcriaNano } from "@llamaindex/liteparse-wasm";await init();
// Downloads this release's model files from Hugging Face and checks their sha256.const ocria = await OcriaNano.fromUrl();
const parser = LiteParse.withOcriaNano({ ocrEnabled: true, outputFormat: "markdown" }, ocria);const result = await parser.parse(pdfBytes);fromUrl option |
Default | |
|---|---|---|
baseUrl |
this release on Hugging Face | where the files are (<baseUrl>/<file>), e.g. your own CDN |
scripts |
all | recognizers to download: "latin" (always), "cjk", "rtl", "world" |
layout |
true |
download LayoutNet (17 MB) for learned tables and layout |
verify |
true |
check each file’s size and sha256 |
OcriaNano.fromUrl({ scripts: ["latin"], layout: false }) is the smallest setup (1.5 MB of models). To cache or bundle
the files yourself, pass their bytes to OcriaNano.load({ det, detMeta, router, recLatin: { onnx, charset }, ... }).
The models are licensed separately from LiteParse under a modified OpenRAIL license.
Custom OCR engines
Section titled “Custom OCR engines”To use any other OCR, pass a custom ocrEngine object with a recognize method:
const parser = new LiteParse({ ocrEnabled: true, ocrLanguage: "eng", // Use more than 1 only if the engine supports concurrent jobs. numWorkers: 2, ocrEngine: { /** * @param imageData PNG-encoded image bytes * @param width rendered page width in pixels * @param height rendered page height in pixels * @param language e.g. "eng" * @returns array of { text, bbox: [x1, y1, x2, y2], confidence } */ async recognize(imageData, width, height, language) { // e.g. call a Web Worker wrapping tesseract.js, or a remote OCR service return [ { text: "Hello", bbox: [10, 20, 80, 40], confidence: 0.98 }, ]; }, },});This lets you plug in any OCR implementation — a Web Worker running tesseract.js, a cloud OCR API, or anything else that returns text with bounding boxes.
LiteParse keeps at most numWorkers calls to recognize active. When one call
finishes, LiteParse prepares and starts the next page without waiting for the
other calls. An OCR engine can send the calls to a Web Worker pool or to
concurrent HTTP requests. Results stay assigned to their source pages when
jobs finish out of order. Active calls can keep up to numWorkers rendered
page rasters in memory, so use a small value for high-DPI documents.
PDF parsing and rendering remain single-threaded in WASM. numWorkers
defaults to 1 and limits concurrent OCR calls. LiteParse does not create
Web Workers. To process OCR jobs in parallel, supply an engine that supports
concurrent jobs.
Config options
Section titled “Config options”All optional, camelCase:
| Option | Type | Default | Description |
|---|---|---|---|
ocrLanguage |
string |
"eng" |
Language code passed to the OCR engine |
ocrEnabled |
boolean |
false |
Run OCR on text-sparse pages. Off by default in WASM — there is no built-in engine, so this does nothing without ocrEngine |
ocrEngine |
object |
— | Custom JS-side OCR engine (see above) |
onOcrPage |
(page: ParsedPage) => void |
— | Early OCR text and boxes during parse(); calls can arrive out of page order |
numWorkers |
number |
1 |
Maximum concurrent OCR calls |
ocrFailureFatal |
boolean |
true |
When false, OCR failures return partial results instead of throwing |
ocrHedgeDelaysMs |
number[] |
[] |
Request-hedging schedule for a remote ocrEngine |
maxPages |
number |
1000 |
Stop after this many pages |
targetPages |
string |
— | e.g. "1-5,10,15-20" |
dpi |
number |
150 (250 with ocria-nano) |
Render DPI for OCR |
outputFormat |
"json" | "text" | "markdown" |
"json" |
Shape of result.text. Also accepts "md". Throws on any other value |
preserveVerySmallText |
boolean |
false |
Keep tiny text that’s normally filtered |
skipDiagonalText |
boolean |
false |
Drop text more than 2° off the nearest right angle |
cropBox |
{ top, right, bottom, left } |
— | Fraction to crop from each side of every page |
pageOrientationCorrections |
{ page, angle }[] |
— | Counter-rotate listed pages (1-based) by the clockwise angle (0/90/180/270) their content appears rotated |
password |
string |
— | Password for protected PDFs |
quiet |
boolean |
false |
Suppress progress logging |
imageMode |
"off" | "placeholder" | "embed" |
"placeholder" |
How image references appear in markdown. Also accepts "none" for off |
extractLinks |
boolean |
true |
Render [text](url) in markdown |
keepHeadersFooters |
boolean |
false |
Keep running header/footer chrome in markdown |
keepClippedText |
boolean |
false |
Keep text hidden by clips (e.g. overflow from fixed-height table cells) |
emitWordBoxes |
boolean |
false |
Per-word sub-boxes on each text item |
The extraction options — extractImages, extractVectorGraphics, extractAnnotations, extractFormFields, extractStructureTree, extractContentBounds, extractXfaPackets, extractTextMetadata, includeComplexity, and renderFormFields — are all available here too, with the same camelCase names and the same false defaults.