PDF multiple pages to JPG fatal error no such file or directory

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
narf
Posts: 3
Joined: 2016-08-03T02:53:57-07:00
Authentication code: 1151

PDF multiple pages to JPG fatal error no such file or directory

Post by narf »

Hi,

I've been busy with it all morning.

What does not work:
  • - Converting filename-multiple-pages.pdf[0] PDF file to JPG
    - Converting filename-multiple-pages.pdf PDF file to JPG

Code: Select all

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:

Code: Select all

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:
  • - Converting filename-multiple-pages.pdf[1] PDF file to JPG (the second page)
    - Converting filename-single-page.pdf PDF to JPG
The used PHP codes:

Code: Select all

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

Code: Select all

<?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
  • ImageMagick v6.7.2.7-5
    Ghostscript 8.70
Does anyone have any idea what to do? I spent all morning to figure this out but I can't and I hope someone with more experience knows a sollution.

A big forward thanks :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PDF multiple pages to JPG fatal error no such file or directory

Post by snibgo »

Your versions of IM and GS are both very old. I suggest you upgrade them both.

[EDIT: I've moved this to the Imagick forum, which seems more appropriate.]
snibgo's IM pages: im.snibgo.com
narf
Posts: 3
Joined: 2016-08-03T02:53:57-07:00
Authentication code: 1151

Re: PDF multiple pages to JPG fatal error no such file or directory

Post by narf »

Thank you snigbo. The hosting provider says more recent versions than currently installed are not compatible with the Directadmin environment. Installing newer versions (which are not tested and approved by Directadmin) can cause errors on the server. We don't want other customers to experience offline time.

Do you know or recommend anything to bypass this problem? Thanks again.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: PDF multiple pages to JPG fatal error no such file or directory

Post by Bonzo »

Do you have access to another server with more recent versions of the software or can you get a friend to try the code out for you?

If it is a software problem I would recommend you change hosts.
narf
Posts: 3
Joined: 2016-08-03T02:53:57-07:00
Authentication code: 1151

Re: PDF multiple pages to JPG fatal error no such file or directory

Post by narf »

Hi Bonzo, the code should work and its definitely a server problem. We found many solutions which do not work on our server configuration. Like I explained in the above, the hosting provider says they are taking a risk installing newer versions because it's not tested on a DirectAdmin environment. My question now is if someone has experience with the lastest versions of ImageMagick and Ghostscript on a DirectAdmin server.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: PDF multiple pages to JPG fatal error no such file or directory

Post by Bonzo »

Just for your information you are not using Imagemagick directly but going through an API that is not developed or maintained by the people who look after Imagemagick. I thought if you could try your code elsewhere with a newer version it would prove whether it was a code or software problem.
Post Reply