Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS and Image not rendering on my PDF #1035

Open
dheyxter opened this issue Feb 28, 2024 · 3 comments
Open

CSS and Image not rendering on my PDF #1035

dheyxter opened this issue Feb 28, 2024 · 3 comments

Comments

@dheyxter
Copy link

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

@arseniomuanda
Copy link

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

@titosobabas
Copy link

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!

@chanakaDe
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants