laravel-pdf
laravel-pdf copied to clipboard
Notices from MPDF seem to lead to exceptions
Describe the bug
Upon certain HTML, MPDF generates a notice (see https://github.com/mpdf/mpdf/issues/853 ) which seems to lead to crashes.
[2020-06-05 14:08:57] production.ERROR: Undefined index: list_style_type (ErrorException(code: 0): Undefined index: list_style_type at /var/www/example/vendor/mpdf/mpdf/src/Tag/BlockTag.php:898)
[stacktrace]
#0 /var/www/example/vendor/mpdf/mpdf/src/Tag/BlockTag.php(898): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8, 'Undefined index...', '/var/www/intran...', 898, Array)
#1 /var/www/example/vendor/mpdf/mpdf/src/Tag.php(243): Mpdf\\Tag\\BlockTag->open(Array, Array, 357)
#2 /var/www/example/vendor/mpdf/mpdf/src/Mpdf.php(13634): Mpdf\\Tag->OpenTag('LI', Array, Array, 357)
#3 /var/www/example/vendor/niklasravnsborg/laravel-pdf/src/LaravelPdf/Pdf.php(57): Mpdf\\Mpdf->WriteHTML(' <div class=\"co...')
#4 /var/www/example/vendor/niklasravnsborg/laravel-pdf/src/LaravelPdf/PdfWrapper.php(42): niklasravnsborg\\LaravelPdf\\Pdf->__construct('<style>\
To Reproduce
- Use faulty HTML
- Laravel crashes
- See error
Expected behavior PDF is still generated, even in case of not 100% valid HTML
Not sure if this an issue of Laravel-PDF or MPDF. Feedback welcome how to solve this properly. Maybe we just have to lower the error reporting level?
@amenk Hey, Iām pretty sure this is an issue of mpdf. Can you provide some faulty HTML that leads to the crashes on your side?
<ul><div><li>Test</li></div></ul>
But I did not yet verify this as isolated example
Steps to reproduce in a fresh Laravel 7.12 project, with laravel-pdf ^4.0
user@computer:~/example/projects$ composer create-project --prefer-dist laravel/laravel laravel- pdf-test
Creating a "laravel/laravel" project at "./laravel-pdf-test"
Installing laravel/laravel (v7.12.0)
...
user@computer:~/example/projects$ composer require niklasravnsborg/laravel-pdf
Using version ^4.0 for niklasravnsborg/laravel-pdf
...
now replace resources/views/welcome.blade.php with
<ul><div><li>Test</li></div></ul>
replace routes/web.php with
<?php
use Illuminate\Support\Facades\Route;
use PDF;
Route::get('/', function () {
$pdf = PDF::loadView('welcome', []);
return $pdf->stream('document.pdf');
});
Open /
This is thrown
ErrorException
Undefined index: list_style_type
At MPDF they claim this is just a notice and not a crash, but when using in Laravel-PDF, it crashes.
Might be because of Laravel's error reporting levels?

@niklasravnsborg How shall we proceed here? Can we catch the exception somehow?
Unfortunately I'm currently not available to investigate further. Maybe you find the cause and provide a fix via pull request?
Niklas
The same thing happens to me in Yii2, I'm desperate, I can't find the solution, the worst thing is that there is no literature in the wen about this. I'm sure it's a Mpdf bug.
This has given me a bit of a hiccup. I'm using a WYSIWYG editor to allow users to edit chapter text. The resulting content is wrapped in a div, and I believe the user can add divs, also.
Chapters are presented to the end-user enumerated; <ol> is the easiest way to get automatic numbering. After finding out that divs in ol tags are not allowed, I tried switching to css counter, but it appears that mpdf doesn't recognize css counter properties.
Finally I settled on adding the count to the content itself. This would seem to break the principle of separating content from presentation.
I'm facing the same issue but for Undefined Index : SELECT

I used hex color (#d1d5db) instead of rgb(209 213 219 / var(--tw-bg-opacity)) and fixed this error
