8

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?

4
  • are you using bootstrap css? Commented Feb 13, 2018 at 5:56
  • yes bootstrap 3 Commented Feb 13, 2018 at 6:02
  • I recommend mPDF. Still not as fancy as I'd like, but better. Commented Feb 15, 2018 at 4:16
  • @parker_codes I don't think they're looking for an alternative, but rather a solution Commented Jul 5, 2022 at 22:05

6 Answers 6

2

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

Sign up to request clarification or add additional context in comments.

4 Comments

How can I use bootstrap grid system with this barryvdh/laravel-dompdf package?
You can't @Sanjaya
there are many other alterntives out there, I don't think the author is asking for alternatives to DOMPDF, but rather a solution to an existing problem.
2

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

Comments

1

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

Comments

0

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' }}">

1 Comment

This solution not working :(
0

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.

Comments

0

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

1 Comment

This solution not working :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.