sdfsdf
This commit is contained in:
@@ -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<boolean> {
|
||||
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<void> {
|
||||
|
||||
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 = "";
|
||||
|
||||
Reference in New Issue
Block a user