@dornick/parsers-pdf
v0.1.0
Published
Lazy pdf.js parser for Dornick. Extracts text from PDF uploads under /user/files/<id>/parsed/.
Readme
@dornick/parsers-pdf
Lazy pdf.js parser for Dornick — extract text from PDF uploads in the browser.
Registers a FileParser that materialises text.txt and by-page.jsonl under /user/files/<id>/parsed/ on first read. The full pdf.js library only downloads when the agent actually reads one of those paths.
Install
npm i @dornick/parsers-pdfPulls in pdfjs-dist (~700 KB gz when loaded). The Dornick shim itself is < 1 KB.
Use
import { Dornick } from "@dornick/core";
import { pdfTextParser } from "@dornick/parsers-pdf";
const dornick = new Dornick({ config, transport });
dornick.parsers.add(pdfTextParser);The agent now sees /user/files/<id>/parsed/text.txt for every uploaded PDF. The first read triggers a one-time load of pdf.js (~700 KB gz, cached after).
Paths produced
| Path | Content |
|---|---|
| text.txt | Whole-document text, page-joined, whitespace-collapsed |
| by-page.jsonl | One JSON object per page: { page: 1, text: "..." } |
Capability gate
requires: ["wasm"] — runs anywhere WebAssembly is supported. The legacy pdf.js entry point includes a fake-worker fallback, so no separate worker URL configuration is needed for v1.
For better perf in production, the integrator can pre-configure a real worker URL:
import * as pdfjs from "pdfjs-dist/legacy/build/pdf.mjs";
pdfjs.GlobalWorkerOptions.workerSrc = "/path/to/pdf.worker.mjs";The parser picks up the integrator's workerSrc if already set.
Pairs nicely with
@dornick/parsers-ocr— for image-only PDFs where text extraction fails.- Use case: Local PDF Q&A
License
MIT — © Dipankar Sarkar
