Home  >  Article  >  Backend Development  >  PHP code to convert PDF to PNG format using imagick library

PHP code to convert PDF to PNG format using imagick library

WBOY
WBOYOriginal
2016-07-25 08:45:471415browse
  1. function pdf2png($PDF,$Path){
  2. if(!extension_loaded('imagick')){
  3. return false;
  4. }
  5. if(!file_exists($PDF)){
  6. return false;
  7. }
  8. $IM = new imagick();
  9. $IM->setResolution(120,120);
  10. $IM->setCompressionQuality(100);
  11. $IM->readImage($PDF);
  12. foreach ($IM as $Key => $Var){
  13. $Var->setImageFormat('png');
  14. $Filename = $Path.'/'.md5($Key.time()).'.png';
  15. if($Var->writeImage($Filename) == true){
  16. $Return[] = $Filename;
  17. }
  18. }
  19. return $Return;
  20. }
复制代码

转成, PDF, imagick


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn