Converting HTML to PDF using Maatwebsite I could not achieve below pdf page setting options. Instead, I switched to laravel-dompdf.
With Laravel DomPDF html convert to pdf with few styling issues which I could fix later
like background-url replaced with img tag and some list replaced with table tag
$options = [
'defaultFont' => 'sans-serif',
'isRemoteEnabled' => TRUE,
'isJavascriptEnabled' => FALSE,
'debugKeepTemp' => TRUE,
'isHtml5ParserEnabled' => TRUE,
'enable_html5_parser' => TRUE,
];
return Pdf::setOptions($options)
->loadHTML($html)
->setWarnings(false)
->setPaper('a3', 'landscape')
->download('export_tickets.pdf');
Laravel dompdf also gives error when using google fonts.
<link
href="https://fonts.googleapis.com/css2?family=Varela+Round&display=swap"
rel="stylesheet"
/>
Two Issues
1)Maatwebsite and dompdf gives error using Google fonts
2)In Maatwebsite How to set following options
'defaultFont' => 'sans-serif',
'isRemoteEnabled' => TRUE,
'isJavascriptEnabled' => FALSE,
'debugKeepTemp' => TRUE,
'isHtml5ParserEnabled' => TRUE,
'enable_html5_parser' => TRUE,
->setWarnings(false)
->setPaper('a3', 'landscape')
Let me address the two points separately:
Issue using Google Fonts
From the first option in this answer, possibly the easiest way to get external font files is to use the
@font-facerule. In your case, this would look like this:Since
laravel-dompdfand Maatwebsite (Dompdf) work similarly, this should work across either of them. (Tested withlaravel-dompdf)Set Maatwebsite PDF Options
Since Maatwebsite uses
PhpSpreadsheet, you can use a custom writer. In your case, this could look something like:To use this writer: