jhoss
jhoss

Reputation: 487

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?

Upvotes: 8

Views: 40984

Answers (6)

AlienForHumans
AlienForHumans

Reputation: 31

Try to set isHtml5ParserEnabled option to true:

PDF::setOptions(['dpi' => 150, 'isHtml5ParserEnabled' => true, 'defaultFont' => 'sans-serif']); 

This will enable HTML5 parser (disabled by default in the package).

Upvotes: 0

Ngugi Kiarie
Ngugi Kiarie

Reputation: 1448

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

Upvotes: 1

reda benlahsen
reda benlahsen

Reputation: 29

You should use another version of bootstrap. because i tested it with bootstrap 3 and it's not working but it works with version 4 of the framework.

Upvotes: 0

Raghu
Raghu

Reputation: 55

Change your file path to this, if CSS and images are not inside the public directory.

<img src="{{ base_path().'/location/to/image/image.png' }}" />
<link rel="stylesheet" type="text/css" href="{{ base_path().'/location/css/bootstrap.min.css' }}">

Upvotes: 0

Salem loress
Salem loress

Reputation: 359

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

Upvotes: 2

Sapnesh Naik
Sapnesh Naik

Reputation: 11636

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

Upvotes: 2

Related Questions