点击here了解更多详情。试试这个:
HTML
<html>
<body>
<form action="ConvertPdfToImg.php" enctype="multipart/form-data" method="post" name="f1">
<input id="templateDoc" name="templateDoc" type="file" />
<input type="submit" />
</form>
</body>
</html>
PHP
$pdfAbsolutePath = __DIR__."/test.pdf";
if (move_uploaded_file($_FILES['templateDoc']["tmp_name"], $pdfAbsolutePath)) {
$im = new imagick($pdfAbsolutePath);
$noOfPagesInPDF = $im->getNumberImages();
if ($noOfPagesInPDF) {
for ($i = 0; $i < $noOfPagesInPDF; $i++) {
$url = $pdfAbsolutePath.'['.$i.']';
$image = new Imagick($url);
$image->setImageFormat("jpg");
$image->writeImage(__DIR__."/".($i+1).'-'.rand().'.jpg');
}
echo "All pages of PDF is converted to images";
}
echo "PDF doesn't have any pages";
}
看来,在某些情况下,ImageMagick的要求安装Ghostscript的,因为否则会抛出一个后记代表世界上为什么失败的错误 – Zsolti 2013-11-06 12:13:31
做setResolution和setImageResolution做不同的事情,并在该文档相同的描述?谢谢,你完全救了我。 – Hissvard 2017-08-31 14:01:04