import type { Buffer } from "node:buffer"; /** * Per-page extraction result. `lineStart` / `lineEnd` are placeholders * for downstream chunking compatibility — we use page index as the * unit of structure, so they map onto the page's `index` and `index+1` * for the chunker. */ export interface PdfPage { /** 1-based page number as displayed in PDF readers. */ pageNumber: number; /** Extracted plain text. Joined item.str values with spaces. */ text: string; /** True if the page yielded no text (image-only / scanned scan). */ isEmpty: boolean; /** Character count of `text` (cheap recall metric for surfaces). */ charCount: number; } export interface PdfExtractionResult { /** All extracted pages. Order matches the document. */ pages: PdfPage[]; /** Total document text (joined with `\n\n` between pages). */ fullText: string; /** Page count from the doc itself (may differ from `pages.length` if a * page failed extraction; we still attempt every page). */ pageCount: number; /** True if at least one page yielded text. False for image-only scans. */ hasText: boolean; /** Doc-level metadata if the PDF carries it. Best-effort. */ metadata: { title?: string; author?: string; subject?: string; keywords?: string; creator?: string; producer?: string; creationDate?: string; modDate?: string; }; } /** * Optional options for {@link extractPdfText}. * * v3.7.13 H1 — `pageRange` lets callers limit which pages get loaded by * pdfjs. Pre-3.7.13, `extractPdfText` ALWAYS iterated `pageCount` pages * even when the caller only wanted pages 1-3 of a 1000-page PDF, then * `obsidian_read_pdf` sliced down to the requested window post-hoc. That * was wasted CPU/memory and a bearer-token DoS vector in `serve-http` * (a client with a valid token could request small page ranges of huge * PDFs to peg the server). Passing the range down to `doc.getPage()` * means we only deserialize the pages we need. */ export interface ExtractPdfTextOptions { /** 1-indexed inclusive page range. `to >= from > 0`. Values are clamped * to the document's actual `pageCount` if out-of-range. When `undefined`, * every page is extracted (legacy behavior, subject to `maxPages` cap * below). */ pageRange?: { from: number; to: number; }; /** * v3.7.16 (Class F sibling of P1-2) — defense-in-depth page cap. Even * when the caller doesn't pass `pageRange`, refuse to process more than * this many pages in one call to bound CPU on adversarial / runaway * inputs. Default 500 (~50-100s on M1 CPU at default extraction speed * for text-only PDFs; far below the OCR pipeline's 200-page cap because * text extraction is ~10x faster per page). Pass * `Number.POSITIVE_INFINITY` to opt out (background-job mode), or pass * an explicit `pageRange` to bypass the default cap. */ maxPages?: number; } /** v3.7.16 (Class F sibling of P1-2) — default safety cap on per-call * PDF text extraction. See {@link ExtractPdfTextOptions.maxPages}. */ export declare const DEFAULT_PDF_MAX_PAGES = 500; /** * Extract text from a PDF buffer. Memory-mode — caller has already * loaded the file. Use `vault.readBinaryFile(relPath)` to get the * buffer with the standard privacy-filter + max-bytes guards * applied. * * Throws on encrypted PDFs without a password or on hard-corrupt files. * Returns empty pages (with `isEmpty: true`) for image-only scans. */ export declare function extractPdfText(buffer: Buffer, opts?: ExtractPdfTextOptions): Promise; export declare function isPdfjsAvailable(): Promise; //# sourceMappingURL=pdf.d.ts.map