我需要从动态(数据库驱动)pdf创建缩略图。我过去曾使用过以下脚本的变体,但现在这似乎对我不起作用(页面只是挂起)。
<?php
require_once('./template/all_includes.php');
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a file to write to
);
$cwd = '/tmp';
$env = array('asdfadf' => '193');
$convert = "convert pdf:- png:-";
$process = proc_open($convert, $descriptorspec, $pipes, $cwd, $env);
fwrite($pipes[0], 'php /var/www/html/domain.co.uk/store/pdf.php');
fclose($pipes[0]);
while(!feof($pipes[1])) $im .= fread($pipes[1], 1024);
fclose($pipes[1]);
$return_value = proc_close($process);
header("Content-Type: image/png");
echo $im;
?>
有人可以帮我解决这个问题吗?非常感谢:)
答案 0 :(得分:0)
Magick可以原生打开PDF:
$im = new MagickWand('file.pdf[3]'); // open page 3 of the PDF
$png = $im->whateverTheMethodIsForPNG();