【问题标题】:Dynamic value in <img>'s src attribute in dompdfdompdf 中 <img> 的 src 属性中的动态值
【发布时间】:2015-07-11 13:28:42
【问题描述】:

我正在为多家公司制作一份 PDF 格式的发票。每家公司都有自己的徽标,他们希望将其放在 pdf 上。为了生成pdf,我使用dompdf。现在,当使用图像的相对路径对 src 属性的值进行硬编码时,它会在 pdf 上完美呈现。例如在codeigniter中:

$this->load->helper(array('dompdf', 'file'));
$html = '<img style = "height: 140px; width: 180px;" src = "images/logo.png" />';
pdf_create($html, 'filename');
$data = pdf_create($html, '', false);

现在,由于图像的相对路径每次都会根据登录的客户端而改变,我试图为 src 属性赋予一个动态值,如下所示:

$this->load->helper(array('dompdf', 'file'));
$html = '<img style = "height: 140px; width: 180px;" src = '; $row->img; $html.=' />';
pdf_create($html, 'filename');
$data = pdf_create($html, '', false);

其中 $row->img 对于特定情况的值为 = images/logo.png。(该值将根据登录者而变化)。

使用上面的代码只会在 pdf 上给我一个空白区域,甚至没有损坏的图像,也没有任何错误消息。请帮助我,因为它已经度过了我美好的一天。

非常感谢您的评论、建议和回答,再次感谢。

【问题讨论】:

    标签: php html codeigniter dompdf


    【解决方案1】:

    试试这个:

    $html = '<img style = "height: 140px; width: 180px;" src ="'.$row->img.'"/>';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 2020-10-05
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多