pdf-php icon indicating copy to clipboard operation
pdf-php copied to clipboard

Incorrect column width calculation in ezTable

Open savioret opened this issue 1 year ago • 0 comments

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);

savioret avatar Jul 02 '23 08:07 savioret