rospdf / pdf-php

Official R&OS PHP Pdf repository
http://pdf-php.sourceforge.net/
Other
136 stars 64 forks source link

Incorrect column width calculation in ezTable #179

Open savioret opened 1 year ago

savioret commented 1 year ago

In some situations the calculation of the automatic column width assignment based on the widest column is not correct. This can also, in some cases, lead into an infinite loop when the incorrect calculated width of the columns are too small.

image

This code shows the problem:

$pdf = new CezPDF('a4');
$pdf->selectFont('Helvetica');

$myoptions = array(
    'width' => $pdf->ez['pageWidth'] - $pdf->ez['rightMargin'] - $pdf->ez['leftMargin'],
    'showHeadings' => 0,
);

$text = str_repeat("lorem ipsum ", 7);
$data = [[$text, $text, $text]];
$pdf->ezTable($data, null, "", $myoptions);

$pdf->ezText("\n");

$text = str_repeat("lorem ipsum ", 8);
$data = [[$text, $text, $text]];
$pdf->ezTable($data, null, "", $myoptions);

$pdf->ezStream();

In this other example we get into an infinite loop:

$pdf = new CezPDF('a4');
$pdf->selectFont('Helvetica');

$myoptions = array(
    'width' => $pdf->ez['pageWidth'] - $pdf->ez['rightMargin'] - $pdf->ez['leftMargin'],
    'showHeadings' => 0,
);
$enum = "One as dasd asd asdas dsa asd saas asdasdasda One as dasd asd asdas dsa asd saas asdasdasda Three"; 

$data = [[$enum, $enum, $enum, $enum]];

$pdf->ezTable($data, null, "", $myoptions);