使用此代码,我尝试将上传的pdf转换为jpg。
$newname = date("U");
$target = "../uploads/";
$temp = "../temp/";
if($_FILES["fileToUpload"]["type"] == "application/pdf") {
print "pdf";
if(move_uploaded_file( $_FILES["fileToUpload"]["tmp_name"], $temp.$_FILES['fileToUpload']['name'])) {
print "pdf saved<br>";
} else {
print "pdf not saved<br>";
}
$filename = basename( $_FILES['fileToUpload']['name'], ".pdf");
print "<br>".$filename."<br>";
if(file_exists($temp.$_FILES['fileToUpload']['name'])) {
print "temp-file exist<br>";
$konv = "/usr/local/bin/convert -debug 'All' ".$temp.$_FILES['fileToUpload']['name']." ".$target.$newname.".jpg 2>&1";
print $konv."<br>";
exec("convert -debug 'All' ".$temp.$_FILES['fileToUpload']['name']." ".$target.$newname.".jpg 2>&1", $output);
if ($return == "0") { echo "<br>Image generation sucssesful<br>"; }
else { echo "<br>Image generation failed<br>"; }
print_r($output);
foreach ( $output as $file )
print "$file<br>";
} else {
print "temp-file doesn't exist";
}
}
PDF保存在临时文件夹中,但图像转换失败,我得到的唯一错误信息是1。
如何获取更多信息性错误消息?
答案 0 :(得分:0)
<?php
$image = new imagick('file.pdf[0]');
$image->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $image;
?>
其中[0]是页码。
pdfinfo将为您提供页码..
exec('/path/to/pdfinfo '.$afilename.' | awk \'/Pages/ {print $2}\'', $output);