Imagick does not open PDF files with the exception "Could not read file"

Trying to open pdf file with php script with error:

Uncaught ImagickException: Failed to read the file in ... 

I am running OS X, Brew, PHP 7.0, php70-imagick --HEAD, ImageMagick --with-ghostscript, GhostScript

The command line test works fine:

 convert 1.pdf 1.jpg 

File permission allowed. Try both the URL and the local file with the realpath function, so the path to the file is also fine. The script works fine if jpeg is open.

 phpinfo() -> ImageMagick supported formats: EPDF, PDF, PDFA, etc. 

UPDATE: Resolved. The solution is below.

+8
source share
3 answers

This issue was related to the path to ghostscript. It is located in "/ usr / local / bin", but this path is not available to Apache. (phpinfo β†’ Apache Environment β†’ PATH)

The solution is to symbolically refer to another path:

  sudo ln -s /usr/local/bin/gs /usr/bin/gs 

OS X El Capitan Note! / Usr / bin / on OS X 10.11+ is protected. You must follow these steps:

 1. Reboot to Recovery Mode. Reboot and hold "Cmd + R" after start sound. 2. In Recovery Mode go to Utilities -> Terminal. 3. Run: csrutil disable 4. Reboot in Normal Mode. 5. Do the "sudo ln -s /usr/local/bin/gs /usr/bin/gs" in terminal. 6. Do the 1 and 2 step. In terminal enable back csrutil by run: csrutil enable 
+15
source

Here is the best way to update the Apache path variable in OS X, which does not require symbolic binding (and therefore there is no need to disable SIP):

https://www.euperia.com/development/solved-php-imagick-unable-to-open-image-pdf

+2
source

I can not comment on the @ matt-sims answer of October 17, 16 at 14:46 because of a reputation below 50, so I am adding another answer. His reference to β€œthe best way to update the Apache path variable in OS X” does not work. However, you can view a cached copy of Google here .

0
source

All Articles