From 07f9f304a4c62ed62b7079a9f7d44a503f5123c4 Mon Sep 17 00:00:00 2001 From: Moritz Weinmann Date: Thu, 25 Jun 2026 13:40:47 +0200 Subject: [PATCH] =?UTF-8?q?fix(wiki-migration):=20pdftotext=20als=20prim?= =?UTF-8?q?=C3=A4ren=20PDF-Extraktor=20nutzen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pdfparser scheitert an "secured" PDFs (Kopier-Schutz ohne Passwort). pdftotext aus poppler-utils umgeht diesen Schutz und extrahiert den eingebetteten Text korrekt. Falls pdftotext nicht verfügbar ist oder nichts liefert, bleibt pdfparser als Fallback erhalten. Co-Authored-By: Claude Sonnet 4.6 --- .../Script/migrate_old_wiki.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/module/knowledgecenter_update/Script/migrate_old_wiki.php b/module/knowledgecenter_update/Script/migrate_old_wiki.php index 767f895..01b2fc1 100644 --- a/module/knowledgecenter_update/Script/migrate_old_wiki.php +++ b/module/knowledgecenter_update/Script/migrate_old_wiki.php @@ -162,6 +162,18 @@ function get_article_files(int $cid): array { function extract_pdf_text(string $filePath): string { if (!file_exists($filePath) || filesize($filePath) === 0) return ''; + + // pdftotext ist robuster bei gesicherten PDFs (nur Kopier-Schutz, kein Passwort) + $pdftotext = trim(shell_exec('which pdftotext 2>/dev/null') ?? ''); + if ($pdftotext !== '') { + $escaped = escapeshellarg($filePath); + $out = shell_exec("$pdftotext -nopgbrk $escaped - 2>/dev/null"); + if ($out !== null && strlen(trim($out)) > 10) { + return preg_replace('/\s+/', ' ', trim($out)); + } + } + + // Fallback: pdfparser try { $parser = new \Smalot\PdfParser\Parser(); $pdf = $parser->parseFile($filePath);