Page 1 of 1

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

Posted: 2016-08-03T03:11:02-07:00
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 :)

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

Posted: 2016-08-03T04:37:15-07:00
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.]

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

Posted: 2016-08-04T01:50:55-07:00
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.

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

Posted: 2016-08-04T02:36:43-07:00
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.

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

Posted: 2016-08-04T04:40:30-07:00
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.

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

Posted: 2016-08-04T05:59:02-07:00
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.