Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dompdf dont load bootstrap css with barryvdh/laravel-dompdf

i use barryvdh/laravel-dompdf in laravel 5.5 and bootstrap css (renamed to pdf.css with small adjustments) to generate a report in pdf this is my header from the report view calling the css:

<!DOCTYPE html>
 <html lang="en">
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
     <link href="{{public_path('css/pdf.css') }}" rel="stylesheet" type="text/css" />            
</head>
<body>   

my controller:

 public function infor(News $news)
    {   

        ...     
        PDF::setOptions(['dpi' => 150, 'defaultFont' => 'sans-serif']);         
        $pdf = PDF::loadView('admin.news_events.pdf');            
        return $pdf->stream('pdfview.pdf');
   
}

Expected view (html5): enter image description here

view generated in pdf :,( enter image description here How could I solve this?

like image 502
jhoss Avatar asked Feb 13 '18 05:02

jhoss


3 Answers

You have to put all css file in style tag to launch your code

like image 90
Salem loress Avatar answered Nov 10 '22 18:11

Salem loress


barryvdh/laravel-dompdf does not support boostrap yet.

Quoting the author:

I highly doubt that DomPDF can handle Bootstrap correctly. If you need better pdf, try: https://github.com/barryvdh/laravel-snappy That used Webkit to render pdf.

See more about the issue here

like image 1
Sapnesh Naik Avatar answered Nov 10 '22 18:11

Sapnesh Naik


I had the same issue, all I did was create another blade file, copied bootstrap.css contents into it (between style tags) , then included it (the file with the css) in the file I wanted to print

like image 1
Michael Kiarie Avatar answered Nov 10 '22 18:11

Michael Kiarie