fix(wiki-migration): pdftotext als primären PDF-Extraktor nutzen

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 <noreply@anthropic.com>
This commit is contained in:
2026-06-25 13:40:47 +02:00
parent 9817fde8c4
commit 07f9f304a4

View File

@@ -162,6 +162,18 @@ function get_article_files(int $cid): array {
function extract_pdf_text(string $filePath): string { function extract_pdf_text(string $filePath): string {
if (!file_exists($filePath) || filesize($filePath) === 0) return ''; 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 { try {
$parser = new \Smalot\PdfParser\Parser(); $parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile($filePath); $pdf = $parser->parseFile($filePath);