【问题标题】:Imagick Failed to read the file PDFImagick 无法读取文件 PDF
【发布时间】:2016-04-12 20:03:04
【问题描述】:

我正在使用 Imagick 并尝试将 pdf 转换为 png。它失败。我的 error_log 显示“读取文件失败”。

示例代码:

$fileone =  $_SERVER['DOCUMENT_ROOT'] . '/' . 'test.pdf';
$image = new Imagick($fileone);
$image->readImage($fileone);
$image->thumbnailImage(300, 0);
echo '<img src="data:image/png;base64,' .  base64_encode($image->getimageblob())  . '" />';

想法?

【问题讨论】:

  • 我假设你已经安装了ghostscript?
  • 是的,为了安全起见,我重新安装并重置了服务器。
  • @Jeremy,你的问题解决了吗?有一样的。
  • @oleg 是的,我的解决方案是完全为 PDF 绕过 imagick,只使用 ghostscript。

标签: php pdf imagick


【解决方案1】:

你需要安装ghostscript

sudo apt-get install ghostscript

【讨论】:

    【解决方案2】:

    我会先用realpath()检查你的文件路径,然后看看文件是否可读。

    $fileone = realpath('test.pdf');
    
    if (!is_readable($fileone)) {
        echo 'file not readable';
    }
    

    如果是多页pdf试试这个

    $image = new Imagick($fileone.'[0]');
    

    【讨论】:

    • 你是在本地运行这个脚本吗? MAMP 还是在服务器上?
    • 是的,它来自 MAMP。从 PNG 或 JPEG 的工作转换就好了。它正好适合 pdf。
    • 也许可以尝试手动重新安装imagick github.com/delphian/drupal-convert-file/wiki/…
    • 是的,我试过了。它没有用。还有其他可能出错的地方吗?
    • 如果是多页pdf,也可以试试$image = new Imagick($fileone.'[0]');
    猜你喜欢
    • 1970-01-01
    • 2017-03-16
    • 2016-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-06
    相关资源
    最近更新 更多