From 70f09fa9da083bf863f476833ec34114425c53ea Mon Sep 17 00:00:00 2001 From: Andreas Knuth Date: Sun, 12 Jul 2026 22:59:21 -0500 Subject: [PATCH] sdfsdf --- vision_runner.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/vision_runner.ts b/vision_runner.ts index d1773c4..fd06178 100644 --- a/vision_runner.ts +++ b/vision_runner.ts @@ -47,7 +47,7 @@ interface Args { api: string; limit: number; only: string | null; - dpi: number; + dpi: number | "auto"; maxPages: number; force: boolean; outDir: string; @@ -73,7 +73,10 @@ function parseArgs(): Args { api, limit: parseInt(get("--limit", "0")!, 10) || 0, only: get("--only"), - dpi: parseInt(get("--dpi", "150")!, 10) || 150, + dpi: ((): number | "auto" => { + const v = get("--dpi", "auto")!; + return v === "auto" ? "auto" : parseInt(v, 10) || 150; + })(), maxPages: parseInt(get("--max-pages", "8")!, 10) || 8, force: a.includes("--force"), outDir: get("--out-dir", path.dirname(input))!, @@ -234,6 +237,19 @@ async function renderPdf(pdfPath: string, dpi: number, maxPages: number, tmpDir: return files; } +/** Hat das PDF eine nennenswerte Textebene? (Hybrid: Werte getippt → 150 DPI + * reicht. Reiner Scan: keine Textebene, Handschrift möglich → 200 DPI.) */ +async function hasTextLayer(pdfPath: string, maxPages: number): Promise { + try { + const { stdout } = await execFileP("pdftotext", ["-l", String(maxPages), pdfPath, "-"], { + timeout: 30_000, maxBuffer: 10 * 1024 * 1024, + }); + return stdout.replace(/\s+/g, "").length > 100; + } catch { + return false; // im Zweifel als Scan behandeln → hohe Auflösung + } +} + // --------------------------------------------------------------------------- // VLM-Aufruf (llama-server, OpenAI-kompatibel, JSON-Schema) // --------------------------------------------------------------------------- @@ -481,8 +497,11 @@ async function main(): Promise { const tmpDir = await fsp.mkdtemp(path.join(os.tmpdir(), "bvs-")); try { - progress(`${tag} … rendere`); - const images = await renderPdf(pdfPath, args.dpi, args.maxPages, tmpDir); + const dpi = args.dpi === "auto" + ? ((await hasTextLayer(pdfPath, args.maxPages)) ? 150 : 200) + : args.dpi; + progress(`${tag} … rendere (${dpi} dpi)`); + const images = await renderPdf(pdfPath, dpi, args.maxPages, tmpDir); let vis: VisionRaw | null = null; let lastErr = "";