Bart
Bart

Reputation: 11

Imagick multiple pages PDF to JPG fatal error

What does not work:

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 ...

When I try this with a sollution found on the webs with fopen and then using readImageFile of the fopen handle:

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

What does work:

The used PHP codes:

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

?>

Installed modules by hosting provider

Does anyone have any idea what to do?

Upvotes: 1

Views: 949

Answers (1)

Bart
Bart

Reputation: 11

After some research I found out that the hosting provider didn't install recent versions. After a few days of testing and debugging they managed to install the latest versions and it all works now. The code in my post is good and can be used by others :).

Upvotes: 0

Related Questions