laravel-dompdf icon indicating copy to clipboard operation
laravel-dompdf copied to clipboard

CSS and Image not rendering on my PDF

Open dheyxter opened this issue 11 months ago • 3 comments

Hello, I have just recently upgraded my Laravel to the latest version, Now I'm having an issue with external CSS and image rendering on my Dompdf. The data works fine but the css and and image are both not working. In my previous version, it worked fine. Now, my project is working on a docker environment and just new to it. The code below is a sample. Thank you

<link rel="stylesheet" type="text/css" href="{{ asset('file.css') }}" media="all">

dheyxter avatar Feb 28 '24 03:02 dheyxter

It´s very easy to fix, just use de absolute path when you a about to uso laravel-dompdf. {{ public_path('img|css') }} //insted of {{ asset('img|css') }}

arseniomuanda avatar Mar 16 '24 08:03 arseniomuanda

It´s very easy to fix, just use de absolute path when you a about to uso laravel-dompdf. {{ public_path('img|css') }} //insted of {{ asset('img|css') }}

But why use public_path? That is not a clean solution!

titosobabas avatar May 25 '24 01:05 titosobabas

<!DOCTYPE html>
<html>
<head>
    <title>Invoice</title>
</head>
<body>
    <h1>Invoice</h1>
    <!-- Base64 Encoded Image -->
    @php
        $imagePath = public_path('images/my-logo.png');
        $imageData = base64_encode(file_get_contents($imagePath));
        $imageSrc = 'data:image/png;base64,' . $imageData;
    @endphp
    <img src="{{ $imageSrc }}" alt="my logo">
</body>
</html>

This fixed my problem. Thanks man. :-)

chanakaDe avatar Jul 29 '24 12:07 chanakaDe