简体   繁体   中英

Imagick Failed to read the file PDF

I'm using Imagick and trying to convert a pdf to a png. It fails. My error_log says "Failed to read the file".

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.

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

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

Then if it is a multiple page pdf try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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