dompdf dont load bootstrap css with barryvdh/laravel-dompdf

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Resolving CSS Issues with Bootstrap and Laravel-DomPDF in PDF Generation The issue of failing to load Bootstrap CSS for PDF generation using barryvdh/laravel-dompdf can be quite frustrating. The process may seem straightforward, but there are several reasons why this might not work as expected. This blog post aims at providing a comprehensive guide on how you can solve this problem and ensure a well-defined and aesthetically pleasing PDF generation with your Laravel application. 1. Verify Your CSS File Path Ensure that the path to your customized Bootstrap CSS file is correct in the `` tag in your view. Replace `{{public_path('css/pdf.css') }}` with the actual path to your CSS file, which could be `{{asset('css/pdf.css') }}, {{asset('storage/css/pdf.css') }}, or simply {{asset('assets/css/bootstrap-pdf.css') }}. 2. Use Proper HTML Structure and Layout The issue might also arise due to an improper HTML structure being passed along to DomPDF. Ensure that your view is marked up correctly with a valid HTML5 doctype, proper head and body tags, and a well-structured layout. This will help maintain the formatting on the PDF side while keeping the code cleaner. 3. Utilize the Laravel Package Assets Helper In addition to the `asset()` helper used in your CSS path in the view, you can also consider using other available asset-related helpers like `mix()`, `public_path()`, and `env('APP_URL').` Using these helpers will further ensure that your paths are correct regardless of whether you're working locally or on a staging/production environment. 4. Check the CSS File Compatibility with DomPDF While Laravel-DomPDF has support for various CSS frameworks, including Bootstrap, it's crucial to verify the compatibility of your customized CSS file with DomPDF. Your PDF generation might fail due to a conflict in styles or even missing CSS rules that are utilized by DomPDF. To avoid this issue, test your custom Bootstrap CSS file using other tools like Firefox View Source Option or Chrome's Developer Tools to ensure it renders correctly on the browser before integrating it with DomPDF. 5. Configure DomPDF to Use Custom Fonts Another reason for issues in CSS loading might be due to fonts incompatibility between Bootstrap and DomPDF. Ensure that you specify the correct font-family or use custom fonts by including them in your application's public assets and setting up their paths accordingly. You can also configure DomPDF to use specific font files using its `setFont()` method, allowing for better CSS compatibility. 6. Refresh Cache and Clear Config Caches On occasion, you might face issues with PDF generation due to caching issues. Ensure that you clear the cache on your Laravel application as well as any browser caches. It's also essential to set up a proper configuration in Laravel for DomPDF by providing correct paths and parameters in `config/dompdf.php`. 7. Use CSS Media Rules for Specific PDF Output If only certain elements or rules are needed for your PDF output, consider using media queries in your customized Bootstrap CSS file. These can help you target specific styles specifically for the PDF output without interfering with other styles required by other output formats like HTML. By following these steps and best practices, you should be able to solve the issue of DomPDF not loading your Bootstrap CSS and successfully generate beautiful and functional PDF reports alongside your Laravel application. Remember that ongoing testing with your customized CSS file and Laravel-DomPDF configuration can help ensure a smooth PDF generation process.