mpdf / mpdf.github.io

mPDF documentation
https://mpdf.github.io
Other
508 stars 160 forks source link

Divide by 0 error in function _tableHeight with negative table bottom margin #177

Closed mikestp27 closed 2 years ago

mikestp27 commented 2 years ago

Hi, mPDF is working really well with most of the HTML and CSS I have. In one case, I get a "divide by 0" error in function _tableHeight. That specific section is a table with a negative bottom margin. The same HTML and CSS work well in browser. I double checked the CSS support at https://mpdf.github.io/css-stylesheets/supported-css.html but couldn't find a clear answer whether this was supported or not... I don't absolutely need the "negative margin" to work.
But it would be nice if mPDF was not causing a "divide by 0".

in function _tableHeight, the following line: if ($remainingpage > $enddiv && $enddiv / $remainingpage < 0.05) { crashes with "divide by 0". $remainingpage is 0 but $enddiv is -0.7 The first part of the if would probably get us out of there before the / 0 but because $enddiv is negative, the first part of the if is positive so $enddiv / $remainingpage is executed and it crashes... $enddiv is calculated just the one line above as such: $enddiv = $this->blk[$this->blklvl]['padding_bottom'] + $this->blk[$this->blklvl]['border_bottom']['w'] + $table['margin']['B']; In my case: $this->blk[$this->blklvl]['padding_bottom'] = 0 $this->blk[$this->blklvl]['border_bottom']['w'] = 0 $table['margin']['B'] = -0.7 causing $table['margin']['B'] to be -0.7

Thank you.

Klap-in commented 2 years ago

Smallest example of html and php which let’s reproduce your case is missing, please add to the issue.

finwe commented 2 years ago

also, report to the main repository.