pdf-php
pdf-php copied to clipboard
Incorrect full justification

In commit 00db904 the condition to call adjustWrapText was removed.
It should be put back.
NOTE: Possible duplicate of #152
This is the condition that was removed:
if (($justification == 'full' && ($orgWidth / 100 * 90) < ($orgWidth - $width)) || $justification != 'full') {
$this->adjustWrapText($parsedText, $orgWidth - $width, $orgWidth, $x, $wordSpaceAdjust, $justification);
}
Example to reproduce same as provided image snapshots:
$pdf = new \Cezpdf('a4', 'portrait');
$pdf->ez['fontSize'] = 10;
$pdf->rectangle(
$pdf->ez['leftMargin'], $pdf->ez['topMargin'],
$pdf->ez['pageWidth'] - $pdf->ez['leftMargin'] - $pdf->ez['rightMargin'],
$pdf->ez['pageHeight'] - $pdf->ez['topMargin'] - $pdf->ez['bottomMargin']);
$pdf->ezText("This text is OUTSIDE a table", 0, ['justification' => 'full']);
$pdf->ezText("This is text to show how full justification behaves in a paragraph. The expected behavior is that the first and the last lines are not fully aligned. This is text to show how full justification behaves in a paragraph. The expected behavior is that the first and the last lines are not fully aligned.", 0, ['justification' => 'full']);
$pdf->ezText("\nThis text is INSIDE a table with no padding at all", 0, ['justification' => 'full']);
$data = [["This is text to show how full justification behaves in a paragraph. The expected behavior is that the first and the last lines are not fully aligned. This is text to show how full justification behaves in a paragraph. The expected behavior is that the first and the last lines are not fully aligned."]];
$pdf->ezTable(
$data,
'',
'',
[
'width' => $pdf->ez['pageWidth'] - $pdf->ez['leftMargin']-$pdf->ez['rightMargin'],
'rowGap' => 0,
'colGap' => 0,
'showHeadings'=>0,
'cols' => [['justification'=>'full']]]
);
$pdf->ezText("\nWe expect both texts to look the same", 0, ['justification' => 'full']);
Putting the condition back seems to fix the problem. I've been doing more testing and seems no collateral problems arise.

Thanks for your help !
This also happens just using ezText when text is fully justified and when the text contains breaklines. This is also fixed in PR #177 :
This code reproduces the problem:
$pdf = new CezPDF('a4');
$pdf->selectFont('Helvetica');
$pdf->ezColumnsStart(['num' => 2, 'gap'=>20]);
$options = ['justification' => 'full'];
// Testing break lines should be considered as last lines
$text1 = "\nLorem ipsum dolor sit amet, vitae et sit posuere metus urna et vitae dolor consectetur adipiscing tristique nec odio id euismod."
."\nCurabitur euismod ex volutpat bibendum eleifend."
."\nDonec pretium pretium nibh."
."\nAt consectetur turpis porta et.\n";
$pdf->ezText($text1, 0, $options);
$pdf->ezColumnsStop();
$pdf->ezStream();