简体   繁体   English

Imagick 无法读取 PDF 文件

[英]Imagick Failed to read the file PDF

I'm using Imagick and trying to convert a pdf to a png.我正在使用 Imagick 并尝试将 pdf 转换为 png。 It fails.它失败。 My error_log says "Failed to read the file".我的 error_log 显示“无法读取文件”。

php信息

Example code:示例代码:

$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())  . '" />';

Thoughts?想法?

你需要安装ghostscript

sudo apt-get install ghostscript

I would first use realpath() to check your file path and then see if the file is readable.我会首先使用realpath()检查您的文件路径,然后查看文件是否可读。

$fileone = realpath('test.pdf');

if (!is_readable($fileone)) {
    echo 'file not readable';
}

Then if it is a multiple page pdf try this然后,如果它是多页 pdf 试试这个

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

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

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