spatie / laravel-pdf

Create PDF files in Laravel apps
https://spatie.be/docs/laravel-pdf
MIT License
728 stars 56 forks source link

[Bug]: CSS Tailwind CSS theme no longer included in PDF #176

Closed hyphen81 closed 3 months ago

hyphen81 commented 3 months ago

What happened?

I had a previously working PDF using tailwind css along with a custom theme.css file that I include in my blade template. I recently upgraded to puppeteer v22.14.0 and had the associated issues with that. I resolved it by upgrading browsershot to 4.2.1 and now my PDF is generated. However, it seems my custom theme css is not being included anymore.

How to reproduce the bug

Here is my file in components/layouts/pdf.blade.php:

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
    <meta charset="utf-8">

    <meta name="application-name" content="{{ config('app.name') }}">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>{{ config('app.name') }}</title>

    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700;900&display=swap" rel="stylesheet">

    @filamentStyles
    <script src="https://cdn.tailwindcss.com"></script>
    <style>
        body {
            font-family: 'Lato', sans-serif;
        }
    </style>

    @vite(['resources/css/app.css', 'resources/css/filament/app/theme.css'])

</head>

<body class="antialiased">
    {{ $slot ?? '' }}
    @yield('content')
</body>

</html>

Running:


        return Pdf::view($reportData['view'], ['data' => $reportData])
            ->margins(8, 12, 16, 12)
            ->orientation(Orientation::Landscape)
            ->disk('s3');

generates the PDF, and appears to contain at least some tailwind styling, but nothing from my custom theme seems to be included particularly custom table styles.

Package Version

1.5.2

PHP Version

8.1

Laravel Version

10.48.20

Which operating systems does with happen with?

Linux

Notes

This is a filament app. Running locally on WSL2, ubuntu v22.04.

hyphen81 commented 3 months ago

I don't know what happened, but this seems to have resolved itself.