Parse methods

The pure-TypeScript block algorithm runs everywhere; LiteParse runs natively in Node or as WASM in browsers and Workers.

options.method picks one of three interchangeable engines:

MethodEngineEnvironmentsOCR
"ts-block-algorithm" (default)This package's own pipelineNode.js, Cloudflare Workers, browserNo
"liteparse"LiteParse, native (@llamaindex/liteparse)Node.js onlyOptional
"liteparse-wasm"LiteParse's WebAssembly build (@llamaindex/liteparse-wasm)Node.js, Cloudflare Workers, browserOptional, through a callback
import { convertPDFToHTML } from 'extract-pdf';

const { html } = await convertPDFToHTML(buffer, { method: 'liteparse' });

// The WASM build also runs in browsers and on Workers:
const { html: same } = await convertPDFToHTML(buffer, { method: 'liteparse-wasm' });

Both LiteParse packages are optional dependencies: install the one you use (bun add @llamaindex/liteparse). If it is missing, convertPDFToHTML resolves to { error } instead of throwing. Both LiteParse paths run with OCR off (ocrEnabled: false) unless you pass liteParseOptions. The WASM build has no OCR engine of its own; pass a liteParseOptions.ocrEngine callback, for example one backed by tesseract.js.

Should this PDF get OCR?

detectPdfNeedsOcr runs a cheap text-layer-only pass and reports whether each page needs OCR or other heavy parsing, so you can route a document before committing to a slow parse. Like "liteparse", it is Node.js only.

import { convertPDFToHTML, detectPdfNeedsOcr } from 'extract-pdf';

const assessment = await detectPdfNeedsOcr(buffer);
// { needsOcr: boolean, pages: PageComplexityStats[], reasons: string[] }

const { html } = assessment.needsOcr
  ? await convertPDFToHTML(buffer, { method: 'liteparse', liteParseOptions: { ocrEnabled: true } })
  : await convertPDFToHTML(buffer, { method: 'liteparse' });

reasons collects every signal found across pages: "scanned", "no-text", "sparse-text", "embedded-images", "garbled" or "vector-text".

On this page