laravel-dompdf: PHP 7.4 'ErrorException: Invalid characters passed for attempted conversion, these have been ignored'

Hi,

First of all - thanks for the package! 😃 I have a project I’m just testing with php 7.4. When it tries to return the pdf it throws an exception :

$pdf = PDF::loadView('order.pdf', ['order' => $order]);

return $pdf->download($order->getPdfName());
ErrorException: Invalid characters passed for attempted conversion, these have been ignored

/Users/me/Documents/code/project/vendor/dompdf/dompdf/lib/Cpdf.php:2545
/Users/me/Documents/code/project/vendor/dompdf/dompdf/lib/Cpdf.php:2669
/Users/me/Documents/code/project/vendor/dompdf/dompdf/src/Adapter/CPDF.php:1006
/Users/me/Documents/code/project/vendor/dompdf/dompdf/src/FontMetrics.php:310
/Users/me/Documents/code/project/vendor/dompdf/dompdf/src/FrameReflower/Text.php:197
/Users/me/Documents/code/project/vendor/dompdf/dompdf/src/FrameReflower/Text.php:372
/Users/me/Documents/code/project/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php:895
/Users/me/Documents/code/project/vendor/dompdf/dompdf/src/FrameReflower/Block.php:845
/Users/me/Documents/code/project/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php:895
/Users/me/Documents/code/project/vendor/dompdf/dompdf/src/FrameReflower/Block.php:845
/Users/me/Documents/code/project/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php:895
/Users/me/Documents/code/project/vendor/dompdf/dompdf/src/FrameReflower/Page.php:141
/Users/me/Documents/code/project/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php:895
/Users/me/Documents/code/project/vendor/dompdf/dompdf/src/Dompdf.php:847
/Users/me/Documents/code/project/vendor/barryvdh/laravel-dompdf/src/PDF.php:195
/Users/me/Documents/code/project/vendor/barryvdh/laravel-dompdf/src/PDF.php:142
/Users/me/Documents/code/project/vendor/barryvdh/laravel-dompdf/src/PDF.php:165

If I make the blade template entirely empty it runs ok - but even if I add ‘hello’ it throws the exception. Only seems to trigger on php 7.4. This on Laravel 6.6.2, PHP 7.4.0, laravel-dompdf 0.8.5.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 19

Most upvoted comments

You need to use dompdf > 0.8.4.

For me, I had to remove my dompdf dependency in my composer file, and then I removed this package and reinstalled, that bumped this package to .9, and then it upgraded dompdf and everything is working again.

Yes I had same issue…updating the package didn’t work but when I ran composer remove barryvdh/laravel-dompdf then composer require barryvdh/laravel-dompdf it seemed to update whatever it needed to update with the fresh install and all working now

https://github.com/dompdf/dompdf/issues/2003 look my fix @barryvdh Can you fork dompdf ? It’s not maintained (or very slow) 2 months no update… Just a quick fix dompdf\lib\Cpdf.php (this fix remove < php5.6 compat too)

if ($c >= 0) { if (ctype_xdigit($c) && ctype_xdigit($n)) { $data['codeToName'][$c] = $n; } $data['C'][$c] = $width; } else { $data['C'][$n] = $width; }

The best practice approach would be to either wait for a 7.4 compatible release or fork the project with the fix you need.