Skip to content

osrforge.preprocess

Stage 0: deterministic PDF preprocessing.

Copies the source into the workdir, renders every page to PNG, extracts every page's text layer, and writes run.json. No model calls — everything here is deterministic code, though PNG byte-stability across pdfium/Pillow versions is explicitly not a contract (assembly purity begins at the cached stage outputs).

preprocess

preprocess(pdf_path: Path, workdir_path: Path, settings: ConversionSettings) -> RunMeta

Run stage 0: copy, render, and extract the source module into a workdir.

Re-running on an existing workdir rebuilds it — pages/ is cleared before rendering so a shorter re-render never leaves stale trailing pages. Skip-if-unchanged logic belongs to rerun, not here.

Parameters:

Name Type Description Default
pdf_path Path

The source module PDF.

required
workdir_path Path

The workdir root to create or rebuild.

required
settings ConversionSettings

The pipeline settings; the full settings echo lands in run.json.

required

Returns:

Type Description
RunMeta

The run metadata, as written to run.json: preprocess completed, all

RunMeta

other stages pending.

Raises:

Type Description
PdfError

If the source is missing, over a configured limit, corrupt, or password-protected (encrypted PDFs are unsupported in v1).