问题描述
我正在尝试将PDF的第一页转换为图像文件.
I am trying to convert the first page of a PDF to an image file.
我有以下代码:
$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
如果我更改:
$im = new imagick('/images/test.pdf[0]');
收件人:
$im = new imagick('/images/test.pdf');
我收到以下错误:
Uncaught exception 'ImagickException' with message 'Unable to read the file
我确定我的PDF路径正确,并且不确定如何解决此问题.谁能帮我这个忙吗?
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?
推荐答案
驱动器的根目录中是否有/images
文件夹?请记住-imagick在PHP中运行,并且不知道您网站的URL空间结构是什么.您需要使用本地文件系统路径,例如
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]');
这篇关于PHP imagick出现PDF问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!