Imagick 多页 PDF 到 JPG 致命错误

Imagick multiple pages PDF to JPG fatal error

什么不起作用:

Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `/path/to/filename-multiple-pages.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/664' in ...

当我使用 fopen 在网上找到的解决方案尝试此操作,然后使用 fopen 句柄的 readImageFile 时:

Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `/tmp/magick-rGGsdy9f': No such file or directory @ error/pdf.c/ReadPDFImage/664'

什么有效:

使用的PHP代码:

<?php

  // this does work for a single page file
  // it does NOT work for multiple page file
  // it does NOT work when using pdffile.pdf[0]
  // it DOES work when using pdffile.pdf[1]

  $filename = '/path/to/pdffile.pdf';  
  $im = new Imagick();
  $im->readImage($filename);
  $im = $im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
  $im->scaleImage(150, 150, true);
  $im->writeImage('/path/to/image/pdffile.jpg');
?>


<?php
  // i used alternative code which gave me the second /tmp/ dir error (see above)

  $filename = '/path/to/pdffile.pdf';    
  $pdf_handle = fopen($filename, 'rb');
  $doc_preview = new Imagick();
  $doc_preview->setResolution(150,150);
  $doc_preview->readImageFile($pdf_handle);
  $doc_preview->setIteratorIndex(0);
  $doc_preview->setImageFormat('jpeg');
  $doc_preview->writeImage('/path/to/image/pdffile.jpg');
  $doc_preview->clear();
  $doc_preview->destroy();

?>

托管提供商安装的模块

有人知道该怎么办吗?

经过一些研究,我发现托管服务提供商没有安装最新版本。经过几天的测试和调试,他们设法安装了最新版本,现在一切正常了。我的post里面的代码很好,可以给别人用:).