Jeremy
Jeremy

Reputation: 554

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 info

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?

Upvotes: 5

Views: 9973

Answers (2)

Eder Nascimento
Eder Nascimento

Reputation: 81

You need to install ghostscript

sudo apt-get install ghostscript

Upvotes: 7

Adam Lynch
Adam Lynch

Reputation: 331

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]');

Upvotes: 2

Related Questions