html2pdf icon indicating copy to clipboard operation
html2pdf copied to clipboard

Fatal error with empty textarea

Open arnoschaefer opened this issue 5 years ago • 2 comments

I am using html2pdf v5.2.1. I encounter the following error with an empty textarea:

$oHtmlToPdf = new Html2Pdf();
$oHtmlToPdf->writeHTML('<h1>Foo</h1><p><textarea></textarea></p>');
Notice: Undefined offset: 0 in /sources/vagrant/vendor/spipu/html2pdf/src/Html2Pdf.php on line 6007
Fatal error: Call to a member function getParam() on null in /sources/vagrant/vendor/spipu/html2pdf/src/Html2Pdf.php on line 6007

This appears to be caused by the empty textarea. When I put a space inside the textarea: <textarea> </textarea>, the error does not occur.

Is this a known problem?

Best Regards,

Arno

arnoschaefer avatar Feb 28 '19 11:02 arnoschaefer

Thanks for this report it is a new issue

spipu avatar Feb 28 '19 11:02 spipu

Hello! This bug is still active at current version 5.2.8. I found how to fix this issue. Add check for variable $level. At line 6026 for version 5.2.8. File vendor/spipu/html2pdf/src/Html2Pdf.php. Current code $prop['value'] = $level[0]->getParam('txt', '');

Fixed code if($level[0]){ $prop['value'] = $level[0]->getParam('txt', ''); }

May you add this code to fix issue?

master-23 avatar Jan 24 '24 10:01 master-23