Imagick不会打开带有

Imagick不会打开带有

本文介绍了Imagick不会打开带有“无法读取文件”的pdf文件。例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试从php脚本打开PDF文件时出现错误错误:

Trying to open PDF file from php script drop into fault with error:

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

我正在运行OS X,Brew,PHP 7.0,php70-imagick --HEAD ,ImageMagick --with-ghostscript,GhostScript

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

命令行测试工作正常:

convert 1.pdf 1.jpg

文件权限正常。尝试使用带有realpath函数的URL和本地文件,因此filepath也可以。如果打开jpeg,脚本工作正常。

File permission is ok. Try both, an URL and local file with realpath function, so filepath is ok too. Script works fine if open jpeg.

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

更新:已解决。解决方案如下。

UPDATE: Solved. Solution below.

推荐答案

这个问题与ghostscript的路径有关。它位于/ usr / local / bin中,但Apache无法使用此路径。 (phpinfo - > Apache Environment - > PATH)

This problem was with path to ghostscript. It's locate in "/usr/local/bin", but this path is not available to Apache. (phpinfo -> Apache Environment -> PATH)

解决方案是将符号链接文件转到另一条路径:

Solution is to symlink file to another path:

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

OS X El Capitan注意! / usr / bin /在OS X 10.11+中受到保护。您必须按照以下步骤操作:

OS X El Capitan Note! /usr/bin/ in OS X 10.11+ is protected. You have to follow this 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

这篇关于Imagick不会打开带有“无法读取文件”的pdf文件。例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 08:32