php imagick库处理pdf有关问题

时间:2017-12-19
执行如下源码:

function pdf2png($PDF,$toPath,$page){   
if(!extension_loaded('imagick')){
echo "imagick";
return false;   
}   
if(!file_exists($PDF)){
echo "noexists";
return false;   
}
$IM = new imagick();   

$IM->setResolution(1000,2000);   

$IM->setCompressionQuality(100);   

$IM->readImage($PDF."[".$page."]");

foreach ($IM as $Key => $Var){
$Var->setImageFormat('png');       
$Filename = $toPath.time().'_'.$Key.'.png';       
if($Var->writeImage($Filename) == true){           
$Return[] = $Filename;       
}
}
return $Return;
}

报如下错误:
 
Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `papers/1375680721.pdf': No such file or directory @ error/blob.c/OpenBlob/2622' in C:\xampp\htdocs\fc\editpaper.php:38 Stack trace: #0 
C:\xampp\htdocs\fc\editpaper.php(38): Imagick->readimage('papers/13756807...') #1 C:\xampp\htdocs\fc\editpaper.php(108): pdf2png('papers/13756807...', 'papers/', 0) #2 C:\xampp\htdocs\fc\editpaper.php(211): anli->insert('') #3 {main} thrown in C:\xampp\htdocs\fc\editpaper.php on line 38

------解决方案--------------------
 
Windows系统下运行,还需要装一个安装软件ghostscript;下载地址:http://downloads.ghostscript.com/public/gs904w32.exe  ; 祝你成功。

上一条:一个高效的敏感词过滤方法(PHP) 下一条:php将pdf生成png缩略图的两种方法:imagick扩展

相关文章

最新文章