PHP uses Imagick to read PDFs and generate PNG thumbnail instances, imagickpng
PDF Generate PNG home thumbnail (server needs to support Imagick)
Copy CodeThe code is as follows:
/**
* Pdf2png
* @param $pdf pending PDF file
* @param $path The path of the picture to be saved
* @param $page the page to be exported-1 for all 0 for the first page 1 for the second page
* @return saved picture path and file name.
*/
function Pdf2png ($pdf, $path, $page =0)
{
if (!is_dir ($path))
{
mkdir ($path, true);
}
if (!extension_loaded (' Imagick '))
{
Echo ' Didn't find imagick! ' ;
return false;
}
if (!file_exists ($pdf))
{
Echo ' did not find pdf ';
return false;
}
$im = new Imagick ();
$im->setresolution (120,120); Set the image resolution
$im->setcompressionquality (80); Compression ratio
$im->readimage ($pdf. " [". $page."] "); Set the first page of the read pdf
$im->thumbnailimage (max., true); Change the size of the image
$im->scaleimage (200,100,true); Scaled small image
$filename = $path. " /". Time (). '. PNG ';
if ($im->writeimage ($filename) = = True)
{
$Return = $filename;
}
return $Return;
}
$s =pdf2png (' file/1371273225-ceshi_ppt.pdf ', ' images ');
echo "";
http://www.bkjia.com/PHPjc/945707.html www.bkjia.com true http://www.bkjia.com/PHPjc/945707.html techarticle PHP uses Imagick to read PDFs and generate PNG thumbnail instances, imagickpng PDF generated PNG home thumbnail (server needs to support Imagick) copy code code as follows:/** * pdf2png * @para ...