The code is as follows:
function pdf2png($pdf,$path,$page=-1) { if(!extension_loaded('imagick')) { return false; } if(!file_exists($pdf)) { return false; } $im = new Imagick(); $im->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="tmp/tmp";//请确保当前目录下有这个文件夹,由于一直要用,所以就不加检测了 $s=pdf2png("./tmp/test.pdf",$path); $scount=count($s); for($i=0;$i<$scount;$i++) { echo "<div align=center><font color=red>Page ".($i+1)."</font><br><a href=\"".$s[$i]."\" target=_blank><img border=3 height=120 width=90 src=\"".$s[$i]."\"></a></div><p>"; }
The pdf file also exists.
An error will be reported when using the Imagick extension to execute the readImage() method. The parallel extension has been added
and ghostscript is also installed under windows. The error is as follows:
AAA David2021-07-10 18:14:23
No error is reported when reporting errors. Installing gshostscript is of no use. Just readimage pictures and PDFs and report errors