TCPDF 不显示带有 writeHTML 的图像 [英] TCPDF don't display image with writeHTML

查看:55
本文介绍了TCPDF 不显示带有 writeHTML 的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题在 TCPDF 上似乎是常青树...
我有一个让我发疯的问题.

this question seems an evergreen on TCPDF...
I have an issue that's driving me crazy.

我有一个 html 代码,用作我的 PDF 的模板",这里有我的公司徽标.
在本地主机 (Windows) 上一切正常,但是当我在线移动时,没有显示图像.
请注意:我的 PDF 上没有任何错误(即 无法获取图像 错误),图像只是空白!
事实上,如果我在 PDF 应该放置的图像位置上单击它,我可以选择它,并且 Adob​​e 启用了复制图像"选项.

I have an html code that I use as "template" for my PDF, here I have my company logo.
Everything works fine on localhost (Windows), but when I move online, the image is not shown.
Pay attention: I don't get any error (ie the Unable to get image error) on my PDF the image is simple blank!
Infact if I click on the PDF on the position where the images it's supposed to be, I can select it, and Adobe enables the option "Copy image".

显然图片存在,在这里,并且许可是正确的.
如果我尝试在那里冲浪,或查看生成的 HTML 页面,一切都很好.

Obviously the image exists, is here, and permission are correct.
If I try to surf there, or view the generated HTML page, everything is fine.

这是PHP代码:

$pdf->SetMargins($params->get('pdfMarginLeft', 15), $params->get('pdfMarginTop', 27), $params->get('pdfMarginRight', 15));
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->SetFont('helvetica', '', 8);
$pdf->AddPage();

$pdf->writeHTML($html, true, false, true, false, '');

$pdf->lastPage();

然后这是我的 HTML 代码(我只是跳过了除图片之外的所有内容):

Then this is my HTML code (I just skipped everything except the image):

<img alt="logo black" src="../images/logo_black.png" height="60" width="210" />

我已经尝试过使用 url(相对和绝对)和路径(相对和绝对),问题仍然存在.有什么想法吗?

I've tried with the url (relative and absolute) and with the path (relative and absolute), the problem still occurs. Any ideas?

推荐答案

由于本地工作正常,因此您可以尝试将图像类型从 png 更改为 jpg 并检查在相应地修改您的代码并将 jpg 上传到服务器后.

As things are working locally so you may try changing the image type from png to jpg and check after modifying your code accordingly and uploading the jpg on the server.

这篇关于TCPDF 不显示带有 writeHTML 的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆