我需要转换pdf到png在php。由于质量原因,我们不想使用Imagemagick,而是更喜欢使用pdftoppm。
为了性能起见,我们更愿意使用的不是文件系统,而是内存。
pdftoppm正确地安装在Ubuntu和works上。
对于另一个项目(html -> pdf),我们使用以下代码:
//input is $html
$descriptorSpec =
[
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w']
];
$command = 'wkhtmltopdf --quiet - -';
$process = proc_open($command, $descriptorSpec, $pipes);
fwrite($pipes[0], $html);
fclose($pipes[0]);
$pdf = stream_get_contents($pipes[1]);
$errors = stream_get_contents($pipes[2]);
if ($errors)
{
$errors = ucfirst(strtr($errors, [
'sh: wkhtmltopdf: ' => '',
PHP_EOL => ''
]));
throw new Exception($errors);
}
fclose($pipes[1]);
$return_value = proc_close($process);
//output is $pdf这是完美的!
但是,如果我使用这段代码对pdftoppm做同样的操作,它不起作用,我做错了什么?
//input is $pdf
$descriptorSpec =
[
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w']
];
$command = 'pdftoppm -png - -';
$process = proc_open($command, $descriptorSpec, $pipes);
fwrite($pipes[0], $pdf);
fclose($pipes[0]);
$png = stream_get_contents($pipes[1]);
$errors = stream_get_contents($pipes[2]);
if ($errors)
{
$errors = ucfirst(strtr($errors, [
'sh: pdftoppm: ' => '',
PHP_EOL => ''
]));
throw new Exception($errors);
}
fclose($pipes[1]);
$return_value = proc_close($process);
//output is $png谢谢你的提示和建议--对不起,我的英语很差。
发布于 2016-05-09 19:27:14
好的,我自己修!
移除连字符。
$command = 'pdftoppm -png ';谢谢大家的支持!
https://stackoverflow.com/questions/37071723
复制相似问题