Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincentsanity's avatar

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">
0 likes
1 reply

Please or to participate in this conversation.