Are you using a CSS framework to style your PDF files ?
DomPDF not working with Sail
I'm switching over our local dev environments from Lando to Laravel Sail. I've been successful so far, but for some reason, the PDFs generated with Laravel DOMPDF are coming out unstyled and with images missing.
Before, with Lando:
After, with Sail:
And here is a snippet of the Blade template that we're using:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ config('app.name', 'IEL Nexus') }}</title>
<!-- Google fonts needed since Font Bunny doesn't work with dompdf -->
<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=Homemade+Apple&family=Roboto:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap" rel="stylesheet">
@vite('resources/css/app.css')
<style>
body {
font-size: 10px;
}
.font-sans {
font-family: 'Roboto', sans-serif;
}
.font-signature {
font-family: 'Homemade Apple', handwriting, cursive;
}
dt {
float: left;
font-weight: bold;
clear: both;
padding-top: 5px;
}
dd {
padding-top: 5px;
text-align: right;
}
.w-third {
width: 33%;
}
.w-fifth {
width: 20%;
}
.w-two-fifths {
width: 40%;
}
.w-quarter {
width: 25%;
}
.w-half {
width: 50%;
}
td {
padding-top: 5px;
}
</style>
</head>
<body class="font-sans">
<table class="w-full border-separate table-fixed border-spacing-2">
<tr>
<td class="w-two-fifths pl-2 align-top">
<img src="{{ asset('images/logo-ratecon.png') }}" alt="RateCon Logo">
</td>
<td class="w-two-fifths px-2 align-top">
<p><strong>Dispatch Sheet</strong></p>
<p>
Integrity Express Logistics<br>
PO Box 42275 - Cincinnati, OH 45242<br>
Tel.: 937-502-1024 Ext: 1024 - Fax: 855-600-2467 - Email: {{ $customer_email }}
</p>
</td>
<td class="w-fifth pl-2 align-top text-right">
<strong>IEL PO#: {{ $po_number }}</strong>
</td>
</tr>
</table>
<!-- and so on… -->
All I can figure out is that some prerequisites aren't installed with Sail by default but are with Lando. Looking at the prerequisites in the underlying DOMPDF package:
I cannot tell which ones are already installed in Sail by default, which I need to add, and how to add them.
I've already published Sail's vendor files so that I can edit docker/8.2/Dockerfile and docker/8.2/php.ini if need be; I just don't know what to put in them. Same with docker-compose.yml.
Can anyone please help me?
Working with Tighten, a highly knowledgeable team of Laravel professionals, I finally have an answer.
I needed to set PHP_CLI_SERVER_WORKERS=3 in my .env file because Sail runs php artisan serve by default, which means that only has a single process. Therefore, it cannot run the web request to render the HTML + the asset fetching from the PDF renderer simultaneously. So, setting this environment variable to a number higher than 1 tells the PHP built-in web server to spin up more workers, which solves this issue.
Please or to participate in this conversation.



