简体   繁体   English

Imagick 不打开带有“无法读取文件”异常的 pdf 文件

[英]Imagick don't open pdf files with “Failed to read the file” exception

Trying to open PDF file from php script drop into fault with error:尝试从 php 脚本打开 PDF 文件时出现错误:

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

I'm running OS X, Brew, PHP 7.0, php70-imagick --HEAD, ImageMagick --with-ghostscript, GhostScript我正在运行 OS X、Brew、PHP 7.0、php70-imagick --HEAD、ImageMagick --with-ghostscript、GhostScript

Command line test works fine:命令行测试工作正常:

convert 1.pdf 1.jpg

File permission is ok.文件权限没问题。 Try both, an URL and local file with realpath function, so filepath is ok too.尝试使用具有 realpath 功能的 URL 和本地文件,因此 filepath 也可以。 Script works fine if open jpeg.如果打开 jpeg,脚本可以正常工作。

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

UPDATE: Solved.更新:已解决。 Solution below.解决方法如下。

This problem was with path to ghostscript.这个问题与ghostscript的路径有关。 It's locate in "/usr/local/bin", but this path is not available to Apache.它位于“/usr/local/bin”中,但该路径对 Apache 不可用。 (phpinfo -> Apache Environment -> PATH) (phpinfo -> Apache 环境 -> PATH)

Solution is to symlink file to another path:解决方案是将文件符号链接到另一个路径:

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

OS X El Capitan Note! OS X El Capitan 注意! /usr/bin/ in OS X 10.11+ is protected. OS X 10.11+ 中的 /usr/bin/ 受到保护。 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

Here is an better way of updating the Apache path variable on OS X which doesn't require symlinking (and therefore no need to disable SIP):这是在 OS X 上更新 Apache 路径变量的更好方法,它不需要符号链接(因此不需要禁用 SIP):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM