You have a quote from a PDF (say, from an LLM's answer) and want to show where it came from. LiteParse finds the words on the page and renders it, so you can crop a screenshot of the passage. Runs in your browser; the PDF is never uploaded.
Open a PDF, or try the sample report.
Paste all or part of the passage. It doesn't need to be exact: punctuation, quote marks, hyphenation and a few changed words are fine.
emitWordBoxes adds a box for every word and extractBlocks groups lines into paragraphs, tables and headings in reading order, so a two-column page reads down each column.targetPages and extractScreenshots renders just that page to PNG at 200 dpi. Boxes are in PDF points (1/72 inch), so pixels = points × 200/72.import init, { LiteParse } from "@llamaindex/liteparse-wasm";
await init();
// 1. Text, word boxes and reading order
const { pages } = await new LiteParse({ emitWordBoxes: true, extractBlocks: true }).parse(pdfBytes);
// pages[i].textItems[j].words[k] = { text, x, y, width, height } (points, top-left origin)
// pages[i].blocks[b].textItemIndices = the items of one paragraph/table, in reading order
// 2. Your matcher returns the page and the boxes of the quoted words
const { pageNum, bbox } = findQuote(quote, pages)[0];
// 3. Screenshot just that page and crop to the box
const shot = (await new LiteParse({ targetPages: String(pageNum), extractScreenshots: true, dpi: 200 })
.parse(pdfBytes)).screenshots[0]; // { imageBytes: PNG, width, height }
const img = await createImageBitmap(new Blob([new Uint8Array(shot.imageBytes)]));
const k = 200 / 72;
ctx.drawImage(img, bbox.x * k, bbox.y * k, bbox.width * k, bbox.height * k, 0, 0, bbox.width * k, bbox.height * k);searchItems(items, { phrase }) may be all you need. It returns whole-line boxes and follows the page's top-to-bottom line order, so it misses a quote that wraps within one column of a multi-column page.ocrEngine (for example Tesseract.js in a worker); its boxes then work the same way. This demo doesn't include one.