import type { Document as MupdfDocument } from 'mupdf'; import { type EmbedderInterface, type FilteredTextFragment } from './pdf-filter.js'; interface StextBbox { x: number; y: number; w: number; h: number; } /** * Shape of mupdf's structured-text JSON used by the per-page loop. * Captured here so both the items-extraction step and the raw `stextJson` * we return remain typed. */ interface StextJson { blocks: Array<{ type: string; lines?: Array<{ text: string; x: number; y: number; bbox?: StextBbox; font: { size: number; name?: string; weight?: string; }; }>; }>; } /** * Per-page record produced by `extractPdfPages`. `text` is the page's text * after semantic header/footer filtering. `textFragments` carries every * survivor's native provenance and exact range in `text`; `stextJson` is the * copied raw mupdf structured-text JSON for downstream visual detection. */ interface ExtractedPage { pageNum: number; text: string; textFragments: FilteredTextFragment[]; stextJson: StextJson; } /** * Result returned by `extractPdfPages`. The helper lifts three concerns * out of the legacy `parsePdf` body: * 1. the per-page `toStructuredText` + `block.type === 'text'` loop; * 2. `filterPageBoundarySentences` for header/footer removal; * 3. title-resolution materials (`metadataTitle` and `page1FontHint`). * * Both `parsePdf` and `parsePdfPages` consume this helper; they differ only * in the `stextOptions` argument they pass to `page.toStructuredText(...)`. */ interface ExtractedPdf { pages: ExtractedPage[]; metadataTitle: string | undefined; page1FontHint: { text: string; fontSize: number; } | undefined; } /** * Per-page extraction shared by `parsePdf` and `parsePdfPages`. * * Takes an already-open mupdf `Document` and: * - reads `info:Title` once, * - iterates pages calling `toStructuredText(stextOptions)`, * - builds `PageData` items (only `block.type === 'text'` lines), * - runs `filterPageBoundarySentences` to drop semantic headers/footers, * - derives `page1FontHint` from page 1's largest-font lines. * * The two callers differ ONLY in `stextOptions`: `parsePdf` passes * `'preserve-whitespace'`; * `parsePdfPages` passes `'preserve-whitespace,preserve-images'` so mupdf * emits `block.type === 'image'` entries for the downstream visual-candidate * detector. * * Lifecycle: this helper does NOT call `doc.destroy()` — disposal stays * with the caller. */ export declare function extractPdfPages(doc: MupdfDocument, embedder: EmbedderInterface, stextOptions: string): Promise; export {}; //# sourceMappingURL=pdf-extract.d.ts.map