@vincentsanity it's either you try to put everything in your tag inside the head tag. Or just use wkhtmltopdf it is much faster and can handle big chunks of data in my point of view it is faster than dompdf. Here is a link for snappy a wrapper for wkhtmltopdf: https://github.com/barryvdh/laravel-snappy
Mar 31, 2020
1
Level 1
Laravel domPDF cant load external css files
I am using domPDF for generating PDF's after a user submit a button. I noticed that if I use
<link rel="stylesheet" href="{{asset('health/css/bootstrap.min.css')}}">
it will not generate PDF and it is always loading forever. I tried to use file_get_contents but seems it is not also working. Can someone tell me what should I do about this? If you know.
Controller
$css = 'health/css/bootstrap.min.css';
$data_type = pathinfo($css, PATHINFO_EXTENSION);
$css_data = file_get_contents($css);
//I can get the image by using this code
$path = 'health/img/logo.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
//for testing view
return view('emails.form',compact('base64','css_data'));
Blade
<link rel="stylesheet" href="{{$css_data}}">
<img src="{{$base64}}" class="img img-fluid img-center">
Please or to participate in this conversation.