php实现pdf转换成图片的方法:首先安装好“GhostScript”;然后使用imagick把PDF转成图片即可。

推荐:《PHP视频教程》
PHP中使用imagick实现把PDF转成图片
PHP Manual里,对imagick的描述,真的是简洁,每个成员函数,点击打开就看到如下文本:
Warning This function is currently not documented; only its argument list is available.
刚才解决了PHP加载问题后,对图片的处理相当方便,网上随便找了一段:
立即学习“PHP免费学习笔记(深入)”;
getImageWidth();
$h = $imagick->getImageHeight();
if ($w > $width || $h > $height)
{
if ($crop)
{
$imagick->cropThumbnailImage($width, $height);
}
else
{
$imagick->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1, true);
}
}
$processed_image = $imagick->getImageBlob();
return $processed_image;
}
$s=resize("123.jpg", 60, 40, 1);
echo $s;
?>但我要用这个扩展做的,是将PDF转成PNG。PDF哦!
一套面向小企业用户的企业网站程序!功能简单,操作简单。实现了小企业网站的很多实用的功能,如文章新闻模块、图片展示、产品列表以及小型的下载功能,还同时增加了邮件订阅等相应模块。公告,友情链接等这些通用功能本程序也同样都集成了!同时本程序引入了模块功能,只要在系统默认模板上创建模块,可以在任何一个语言环境(或任意风格)的适当位置进行使用!
setResolution(120,120);
$im->setCompressionQuality(100);
if($page==-1)
$im->readImage($pdf);
else
$im->readImage($pdf."[".$page."]");
foreach ($im as $Key => $Var)
{
$Var->setImageFormat('png');
$filename = $path."/". md5($Key.time()).'.png';
if($Var->writeImage($filename) == true)
{
$Return[] = $filename;
}
}
return $Return;
}
$path="images";//请确保当前目录下有这个文件夹,由于一直要用,所以就不加检测了
$s=pdf2png("test.pdf",$path);
$scount=count($s);
for($i=0;$i<$scount;$i++)
{
echo "Page ".($i+1)."
@@##@@";
}
?>
跟上面的差不多吧?可是总是不成功,readImage那边异常了,查看错误输出:
PHP Fatal error: Uncaught exception 'ImagickException' with message 'PostscriptDelegateFailed `test.pdf': No such file or directory'
百度谷歌了好久,最后灵机一动,不是说Postscript么?我找,我装。
这个Postscript,其实是GhostScript。
装好后,一跑,OK啦!










