الحصول على نتائج pdftotext إلى متغير فب، وليس ملف نصي

StackOverflow https://stackoverflow.com/questions/1422160

  •  07-07-2019
  •  | 
  •  

سؤال

وpdftotext يأخذ ملف PDF وتحويل النص إلى ملف txt.

وكيف لي أن التوجه نحو الحصول على pdftotext لإرسال النتيجة إلى متغير PHP بدلا من ملف نصي؟

وأفترض لدي لتشغيل exec('pdftotext /path/file.pdf')، ولكن كيف يمكنني الحصول على النتيجة مرة أخرى؟

هل كانت مفيدة؟

المحلول

وتحتاج لالتقاط المعياري / ستدير:

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 -");

وو- سوف يكلف pdftotext لإرجاع النتيجة إلى المعياري بدلا من ذلك إلى الملف.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top