pdftotext獲取PDF文件並將文本轉換爲.txt文件。將pdftotext的結果獲取到php變量中,而不是文本文件
我該如何去獲得pdftotext將結果發送到PHP變量而不是文本文件?
我假設我必須運行exec('pdftotext /path/file.pdf')
,但是如何獲得結果?
pdftotext獲取PDF文件並將文本轉換爲.txt文件。將pdftotext的結果獲取到php變量中,而不是文本文件
我該如何去獲得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返回結果,而不是到stdout到一個文件中。
我的'pdftotext'命令沒有在'exec()'函數中運行。我錯過了在圖書館使用的任何東西嗎? – 2012-08-31 11:50:39
@SumitMadan什麼都可以在exec()中爲你運行。如果沒有,那麼你的問題在那裏,如果其他人運行,然後檢查以確保安裝pdftotext ... – Jason 2012-08-31 12:46:26
其他命令正在運行,並且安裝了pdftotext。 – 2012-09-01 04:01:02