I’m attempting to convert PDF files into PNGs. It works great from the command line (I do have GhostScript 8.64 installed). But from PHP I’m having a problem:
code:
$im = new Imagick($pdf_file); // this is where it throws the exception below
output:
Fatal error: Uncaught exception ‘ImagickException’ with message ‘Postscript delegate failed `23_1235606503.pdf’: No such file or directory @ pdf.c/ReadPDFImage/612′ in get_thumbnail.php:93
Stack trace:
\#0 get_thumbnail.php(93): Imagick->__construct(’…’)
etc. etc.
I'm not sure what I'm doing wrong here, but I suspect it has something to do with my server configuration somewhere. I'm running: Apache 2.2.11 PHP 5.2.8 ImageMagick 6.4.8-9 GhostScript 8.64
The ghostscript interpreter is used by ImageMagick and GraphicsMagick to convert Postscript and similar formats into images.
ImageMagick is a great customizable tool for converting PDF files to individual image files with a single command.
Finally figured this out. The GhostScript executable (gs
) wasn't in Apache's environment path. It was in /usr/local/bin
. Though I tried several ways to add /usr/local/bin
to the path, I did not succeed. I ended up putting a symlink for gs
in the /usr/bin directory
. Now everything works perfectly.
I don't have the "reputation" on Stackoverflow to add a comment inline above, but there is an extra step I had to perform to get this working on my Mac with the latest Sierra update.
When you enter the command:
sudo ln -s /usr/local/bin/gs /usr/bin/gs
On the Mac, you may get the error, "Operation not Permitted".
Apparently Apple made a change that the "bin" directory is not editable, unless you disable SIP (System Integrity Protection).
So here are the steps to do that:
crutil disable
and press "Enter"I just went through these steps and now my Ghostscript works great and I successfully converted a PDF to JPG.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With