简体   繁体   中英

CodeIgniter: how to pass css Bootstrap using dompdf

I am trying to generate a PDF file using codeIgniter and dompdf . The script below creates the PDF file, but the css are not shown. The script below generates only the HTML structure.

    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?

<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

<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.

You must have figured out this issue since it was asked X years ago. But I found the solution via this 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]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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