Imagick多页PDF到JPG致命错误


Imagick multiple pages PDF to JPG fatal error

什么不起作用:

  • 将文件名多页.pdf[0]pdf文件转换为JPG
  • 将filename-multiple-pages.pdf pdf文件转换为JPG

致命错误:未捕获异常"ImagickException",消息为'Postscript委派失败`/path/to/filename multiple pages.pdf':否这样的文件或目录@error/pdf.c/ReadPDFImage/664'在。。。

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

致命错误:未捕获异常"ImagickException",消息为'Postscript委托失败`/tmp/magick-rGGsdy9f':没有这样的文件或目录@error/pdf.c/ReadPDFImage/664'

什么有效:

  • 将文件名转换为多页.pdf[1]pdf文件到JPG(第二页)
  • 将filename-single-page.pdf pdf转换为JPG[/list]

使用的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();
?>

托管提供商安装的模块

  • ImageMagick v6.7.2.7-5
  • Ghostscript 8.70

有人知道该怎么办吗?

经过一些研究,我发现托管提供商没有安装最新版本。经过几天的测试和调试,他们安装了最新版本,现在一切正常。我帖子中的代码很好,其他人可以使用:)。