TCPDF 错误:[图像] 无法获取图像
我使用 TCPDF 和 Drupal 的 print 模块来生成文章的 PDF,以及当我单击链接生成 PDF 时,最终出现以下错误消息:
TCPDF ERROR: [Image] Unable to get image: http://localhost/pathToDrupal/themes/bartik/logo.png
图像存在于指定位置。 我尝试
allow_url_fopen = On;
allow_url_include = On;
在 php.ini 中应用:但这无法解决问题。
请帮忙:(
I'm using TCPDF with Drupal's print module to generate PDF of articles, & ending up with following error message when I click the link to generate PDF:
TCPDF ERROR: [Image] Unable to get image: http://localhost/pathToDrupal/themes/bartik/logo.png
The Image exists in the location specified.
I tried applying:
allow_url_fopen = On;
allow_url_include = On;
in php.ini
but that could not resolve the problem.
Please care to help :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
显然 TCPDF 不使用“fopen”包装器。
如果您提供图像的 URL,TCPDF 会尝试使用 cURL 将其下载到存储 TCPDF 安装的“缓存”目录中(您必须检查
K_PATH_CACHE
常量包含的内容当然)。所以我想你必须在这个目录中有写权限才能发挥作用。您还需要启用 cURL。
Apparently the "fopen"-wrappers are not used by TCPDF.
If you supply the URL of an image, TCPDF tries to download it with cURL into the "cache"-directory where your TCPDF-installation is stored (you have to check what the
K_PATH_CACHE
-constant contains to be sure).So I guess you have to have write permissions in this directory that the magic works. Also you need cURL enabled.
我们的 Linux“example.com”服务器中处理连接的方式存在问题。所以这导致我们在服务器上进行尝试:
每当 TCPDF 尝试使用curl下载图像时,都找不到该图像,但是我们可以通过直接在浏览器中打开它来查看该图像(例如 http://www.example.com/image.jpg)。
我们通过将 example.com VirtualHost 设置为接受 127.0.0.1 连接并将行“127.0.0.1 example.com”添加到 /etc/hosts 来解决该问题。
We had problems with the way connections were handled in our linux "example.com" server. So this lead us to try on the server:
Whenever TCPDF tried to download an image with curl, the image was not found, nevertheless, we could view the image by just opening it directly in the browser (e.g. http://www.example.com/image.jpg).
We solved the problem by setting the example.com VirtualHost to accept 127.0.0.1 connections and adding the line "127.0.0.1 example.com" to /etc/hosts.
只需使用图像路径“images/your_image.png”而不是“http://yourdomain.com/images/your_image.png< /a>”在 PDF html 中。
Just use the image path as "images/your_image.png" instead of "http://yourdomain.com/images/your_image.png" in the PDF html.
我发现当 src 是绝对链接时,TCPDF 会抛出 Unable to get Image: 错误。只需更改为相对链接即可成功创建 PDF。
I've found that TCPDF would throw the Unable to get Image: error when the src was an absolute link. Just changing to a relative link would successfully create the PDF.
我在临时服务器上遇到了这个问题,其中站点的文档根受 .htaccess 文件保护(以防止搜索引擎索引和其他混乱)
tcpdf 使用curl 来获取图像,如果无法访问该文件,则会出现此错误。
为了解决这个问题,我向 .htaccess 添加了一条规则以允许来自网络服务器的请求
I had this problem on a staging server where the docroot of the site was protected by an .htaccess file (to prevent search engine indexing and other confusions)
tcpdf uses curl to fetch the image and it gives this error if it cannot access the file.
To solve it, I added a rule to .htaccess to allow requests from the webserver
尝试按当前工作目录添加路径。
Try to add path by current working dir.
在您的字体 unicode 问题中,您需要放置此语法代码:
将其放在添加页面之前...
In your font unicode problems you need to put this syntax code:
put it before you add the page...
在 drupal 中,请确保在您的函数中包含 tcpdf 库,而不是在模块文件的顶部,否则您将收到此错误。
In drupal be sure to include the tcpdf library in your function and not at the top of your module file or you will get this error.
也试试这个
try this also
扩大错误。它似乎也无法处理 Base64 嵌入图像。这对我来说是一个大问题。
To expand on the error. It also seems to fail with base64 embedded images. This is a big problem for me right now.
将 PHP 5.5 升级到 5.6 后,由于图像错误,我损失了几个小时,
我从 @caligari 找到了解决方案(对已接受答案的评论),它为我解决了问题:
像这样安装 CURL:
After I upgraded PHP 5.5 to 5.6, I lost hours because of an image error,
I found the solution here from @caligari (a comment on the accepted answer) and it fixed the problem for me:
install CURL like this:
就我而言,我尝试了
“curl:(60) 服务器证书验证失败”。被展示了。所以这只是一个证书问题。
In my case I tried to
and the "curl: (60) server certificate verification failed." was shown. So it was simply a certificate issue.