PHP imagick with PDF issue

我的未来我决定 提交于 2020-01-07 05:29:10

问题


I am trying to convert the first page of a PDF to an image file.

I have the following code:

$im = new imagick('/images/test.pdf[0]');

$im->setImageFormat("jpg");
$page=$im->queryFormats();
echo "<pre>";
 print_r ($page);
echo "</pre>";

However, I get an error message saying:

Uncaught exception 'ImagickException' with message 'unable to open image

If I change:

$im = new imagick('/images/test.pdf[0]');

to:

$im = new imagick('/images/test.pdf');

I get the following error:

Uncaught exception 'ImagickException' with message 'Unable to read the file

I am sure the path to my PDF is correct and I'm not sure how to solve this. Can anyone help me out with this?


回答1:


Do you have a /images folder in the ROOT of your drive? Remember - imagick is running within PHP and has no clue whatsoever what your site's URL-space structure is. You need to use the local file system path, e.g.

$im = new imagick('/path/to/example.com/html/images/test.pdf[0]');


来源:https://stackoverflow.com/questions/15955013/php-imagick-with-pdf-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!