Skip to content
Lamina PDF
0.9.0
GitHub
Open the web app

extractWithModels

function extractWithModels<F>(
doc,
options,
models,
__namedParameters?
): Promise<ExtractResult[F]>;

Defined in: packages/sdk/src/extract-job.ts:221

Runs an extraction whose models the host runs asynchronously: steps a job, and for each request awaits the matching function of models, then hands its result back.

F extends ExtractFormat

Document

ExtractJobOptions<F>

HostModels

number = 16

AbortSignal

Promise<ExtractResult[F]>

const json = await extractWithModels(
doc,
{ format: "json", models: { layout: { name: "my-layout", version: "1", sha256, licence: "Apache-2.0" } } },
{ layout: async ({ page, dpi }) => myModel.detect(await render(page, dpi)) },
);

On a document opened with Document.openRange, a step that needs bytes not yet fetched ends the job with data-pending, as every error ends a job; fetch the file first (await doc.ensure(() => doc.pages) reads only the page tree, so read the whole file for a long extraction), or wrap the call in doc.ensure, which runs it again, models included.

LaminaPdfError as ExtractJob.step; invalid-argument when options.models names a model models has no function for; cancelled once signal aborts, also when the model rejects because of it (the model’s error is the cause).

0.2.0