pdf-to-image: Failed to read file error
When converting a PDF (via Media Library Conversion) I get the error ‘Failed to read file’:
"message": "Failed to read the file",
"file": "/Users/samjones/Desktop/DEVELOPMENT/Safe/system/vendor/spatie/pdf-to-image/src/Pdf.php",
"line": 40,
"trace": [
{
"file": "/Users/samjones/Desktop/DEVELOPMENT/Safe/system/vendor/spatie/pdf-to-image/src/Pdf.php",
"line": 40,
"function": "__construct",
"class": "Imagick",
"type": "->",
"args": [
"/Users/samjones/Desktop/DEVELOPMENT/Safe/system/storage/medialibrary/temp/Vrc0otFnhMccJQ61BaGu96DUtVk1cwJs/c0ZJJdOuTNlTDeyZ.pdf"
]
},
...
]
File is there and permissions seem ok, PHP 7.1 and latest ImageMagick 7.0.7-0.
Any ideas?
UPDATE: after restarting the server and reinstalling ImageMagick I’m now getting an error with GhostScript (which presumable ImageMagick is delegating the conversion to.
FailedToExecuteCommand 'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' '-sOutputFile=/var/tmp/magick-266Xh1FBuVfcugv%d' '-f/var/tmp/magick-266OVALiKuMKxoy' '-f/var/tmp/magick-266dsJDEkjrkKzd'' (1) @ error/pdf.c/InvokePDFDelegate/291
GhostScript is installed and working on the command line but it seems ImageMagick is struggling with it?!
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 16
Might be the same issue as I faced this afternoon. Are you testing this locally on your mac? If so, it’s possible that apache can’t access the ghostscript path. It’s located in
/usr/local/bin/gsand it should be symlinked to/usr/bin/gsby running this command:sudo ln -s /usr/local/bin/gs /usr/bin/gs.If you face any permission errors while creating the symlink, please follow the steps as mentioned in the accepted answer for this question on Stackoverflow: https://stackoverflow.com/questions/37927247/imagick-dont-open-pdf-files-with-failed-to-read-the-file-exception
Please let us know if this fixed your issue.
Holy shit. I love you.
Can’t believe I hadn’t seen this SO question (after hours of pulling my hair out). Had to do the funky recovery mode stuff but it worked first time after adding in that symlink.
Might be worth a foot note in the readme, seems like it could be a pain point for certain Mac users? Both iMagick and GhostScript were installed via HomeBrew so could be the issue? ¯\_(ツ)_/¯
You sir are on my ‘owe you a beer’ list.
If you’re using Laravel Herd, the php-fpm.conf file you’re looking for should be located here:
~/Library/Application\ Support/Herd/config/fpmBasically:
cd ~/Library/Application\ Support/Herd/config/fpmand then (in my case)
nano 8.2-fpm.confand then add to the end of the line:
env[PATH] = /usr/local/bin:/usr/bin:/binIf you’re using Homebrew, the env path would probably be:
env[PATH] = /opt/homebrew/bin:/usr/local/bin:/usr/bin:/binbetter late than never: with the latest pdf-to-image at the time of writing 2.2.0 (on windows) all that is needed is installing ghostcript renaming or copying the command line executable (in my case gswin64c.exe) to gs.exe and adding the location of that executable to the windows path.
@vimalmistry Are you sure ghostscript is installed? Maybe it installed in a different path for you. You might want to try
which gsto find out in what directory ghostscript is located. Then replace/usr/local/bin/gswith the path you get from that command.Great to hear, glad I could be of any help. Enjoy working on your application and I’ll make sure I don’t forget about that beer 😉
I also owe you a beer. Thanks -
sudo ln -s /usr/local/bin/gs /usr/bin/gsworked for us too.