简体   繁体   English

CodeIgniter:如何使用 dompdf 传递 css Bootstrap

[英]CodeIgniter: how to pass css Bootstrap using dompdf

I am trying to generate a PDF file using codeIgniter and dompdf .我正在尝试使用codeIgniter 和 dompdf生成 PDF 文件。 The script below creates the PDF file, but the css are not shown.下面的脚本创建 PDF 文件,但没有显示 css。 The script below generates only the HTML structure.下面的脚本只生成 HTML 结构。

    public function create_pdf() {   

    $this->load->view('invoice');    
    $html = $this->output->get_output();         

    $this->load->library('dompdf_gen');

     //Convert to PDF
     $this->dompdf->load_html($html);
     $this->dompdf->render();
     $dompdf = new DOMPDF();
     $this->dompdf->stream("welcome.pdf",array('Attachment'=>0));

}

How can I include following css in the script?如何在脚本中包含以下 css?

<link href="<?php echo base_url('assets/css/bootstrap.css');?>" rel="stylesheet" />
<link href="<?php echo base_url('assets/css/style.css');?>" rel="stylesheet"/  >

I use CodeIgniter and dompdf together and I include my CSS file by simply adding a link tag into the head of the view of I am printing ie我一起使用 CodeIgniter 和 dompdf,我通过简单地将链接标签添加到我正在打印的视图的头部来包含我的 CSS 文件,即

<link rel="stylesheet" type="text/css" href="<sitename>/full/path/to/print.css">

I do only link a basic CSS file in though so I would try a basic CSS file to start with (a file that just puts all the text in bold or something) and then if that works gradually add more rules as the issue could be your CSS files contain something which dompdf cannot handle.我只链接了一个基本的 CSS 文件,所以我会尝试一个基本的 CSS 文件开始(一个文件只是将所有文本以粗体或其他内容),然后如果可行,请逐渐添加更多规则,因为问题可能是你的CSS 文件包含 dompdf 无法处理的内容。

You must have figured out this issue since it was asked X years ago.自从 X 年前被问到这个问题时,您一定已经弄清楚了。 But I found the solution via this github issue .但我通过这个github issue找到了解决方案。 Maybe, someone who's looking for the issue, this might be useful.也许,正在寻找问题的人,这可能很有用。

Tried & Tested by me.由我尝试和测试。 💹 💹

Worked for me.为我工作。 💹 💹

将 dompdf 的实例作为

$dompdf = new Dompdf\Dompdf(['isRemoteEnabled' => true]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM