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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user