الحصول على نتائج pdftotext إلى متغير فب، وليس ملف نصي
-
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 لإرجاع النتيجة إلى المعياري بدلا من ذلك إلى الملف.
لا تنتمي إلى StackOverflow