【问题标题】:Html2Pdf -Codeigniter -Image not loadingHtml2Pdf -Codeigniter -图像未加载
【发布时间】:2017-10-28 09:08:11
【问题描述】:

我正在为 codeigniter 使用 HTML2PDF 库

见:https://github.com/aiwmedia/HTML2PDF-CI 我的问题是我无法使用标签加载图像。它总是显示 alt 属性,而不是图像。尝试给出完整路径和相对路径。

查看:

<img src="<?php echo base_url(); ?>/uploads/pdf_images/1.jpg" alt="<?php echo base_url(); ?>uploads/pdf_images/1.jpg"/>

控制器:

$this->load->library('html2pdf');
$this->html2pdf->folder(APPPATH."third_party/samples/");
$file_name=$this->random_string(7);
$this->html2pdf->filename($file_name.'.pdf');
$this->html2pdf->paper('a4', 'portrait');
//$this->html2pdf->html($this->load->view('pdfcouple',$data,true));
if($user_details_arr[0]->is_married)
{
    $content=$this->load->view('pdfcouple', $data, true);
}
$this->html2pdf->html($content);
$this->html2pdf->create('save');

【问题讨论】:

  • 你检查过,那个baseurl有一个名为uploads的子文件夹吗?您还可以尝试对图像进行 base64 编码并嵌入完整数据,而不仅仅是位置。
  • baseurl 有一个名为 uploads 的子文件夹。让我检查一下建议的其他解决方案。
  • 你试过base64内容吗,别名src="data:image/jpg;base64,{$base64contentofyourimage}"
  • 试过了: "/> 不工作
  • 请尝试&lt;img src="&lt;?php $path = base_url() .'/uploads/pdf_images/1.jpg'; $type = pathinfo($path, PATHINFO_EXTENSION); $data = file_get_contents($path); echo 'data:image/' . $type . ';base64,' . base64_encode($data); ?&gt;"&gt;&lt;/img&gt;

标签: php codeigniter html2pdf


【解决方案1】:

我通过编辑 dompdf_config.custom.inc.php 解决了这个问题

未注释

define("DOMPDF_ENABLE_REMOTE", true);

现在图像正在加载到 pdf 中。感谢您的支持。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-21
    • 1970-01-01
    • 1970-01-01
    • 2013-01-10
    • 2022-11-02
    • 2021-09-08
    • 1970-01-01
    • 2017-10-23
    相关资源
    最近更新 更多