王盛博客 - 网圣课堂 - 金萝卜 - PDF转PNG
type: channel
link: https://wangsheng.cc/tag/PDF%E8%BD%ACPNG/
items: PHP把PDF转PNG

PHP把PDF转PNG
type: item
date: 2021-12-03T17:35:00+08:00
description: <? function pdf2png($pdf, $path) { if (!extension_loaded('imagick')) { return false; } if (!file_exists($pdf)) { return false; } $im = new Imagick(); $im->setResolution(80, 80); //设置分辨率 值越大分辨率越高 $im->setCompressionQuality(100); $im->readImage($pdf); $m=md5($pdf); foreach ($im as $k => $v) { $v->setImageFormat('png'); $fileName = $path . $m.'.'.$k. '.png'; if ($v->writeImage($fileName) == true) { $return[] = $fileName; } } return $return; }{card-default label="使用方法" width="100%"}//用法 var_dump(pdf2png('1.pdf','test/')); /*返回 array(15) { [0]=> string(43) "test/f690229642a2b8bc66e9fbb05793266b.0.png" [1]=> string(43) "test/f690229642a2b8bc66e9fbb05793266b.1.png" [2]=> string(43) "test/f690229642a2b8bc66e9fbb05793266b.2.png" [3]=> string(43) "test/f690229642a2b8bc66e9fbb05793266b.3.png" [4]=> string(43) "test/f690229642a2b8bc66e9fbb05793266b.4.png" } */{/card-default}