Php değişken içine pdftotext sonuçlarını alma, bir metin dosyası değil

2 Cevap php

pdftotext bir PDF dosyasını alır ve bir. txt dosyasına metin dönüştürür.

Nasıl bir PHP değişkeni yerine bir metin dosyasına sonucu göndermek için pdftotext alma hakkında gitmek istiyorsunuz?

Ben exec('pdftotext /path/file.pdf') çalıştırmak zorunda varsayarak yaşıyorum, ama nasıl bir sonuç geri alabilirim?

2 Cevap

Sen stdout / stderr yakalamak gerekiyor:

function cmd_exec($cmd, &$stdout, &$stderr)
{
    $outfile = tempnam(".", "cmd");
    $errfile = tempnam(".", "cmd");
    $descriptorspec = array(
        0 => array("pipe", "r"),
        1 => array("file", $outfile, "w"),
        2 => array("file", $errfile, "w")
    );
    $proc = proc_open($cmd, $descriptorspec, $pipes);

    if (!is_resource($proc)) return 255;

    fclose($pipes[0]);    //Don't really want to give any input

    $exit = proc_close($proc);
    $stdout = file($outfile);
    $stderr = file($errfile);

    unlink($outfile);
    unlink($errfile);
    return $exit;
}
$result = shell_exec("pdftotext file.pdf -");

- bir dosyaya yerine stdout sonucu geri dönmek için pdftotext talimat verir.