spipu/html2pdf

text-align: justify does not work with Unicode fonts

eremem opened this issue · 0 comments

There seems to be some fundamental problem in the current implementation of the text justification and Unicode fonts - it simply doesn't work unlike text-align: left and text-align: right.

The following code shows this issue by using one of the default fonts:

$html2pdf = new \Spipu\Html2Pdf\Html2Pdf('P', 'A4', 'en');
$html2pdf->setDefaultFont('dejavusans');
$html2pdf->writeHTML('<page>' .
	'<p style="text-align: justify;">Aenean placerat. In vulputate urna eu arcu. Aliquam erat volutpat. Suspendisse potenti. Morbi mattis felis at nunc. Duis viverra diam non justo. In nisl. Nullam sit amet magna in magna gravida vehicula. Mauris tincidunt sem sed arcu. Nunc posuere. Nullam lectus justo, vulputate eget, mollis sed, tempor sed, magna. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam neque. Curabitur ligula sapien, pulvinar a, vestibulum quis, facilisis vel, sapien. Nullam eget nisl. Donec vitae arcu.</p>' .
	'</page>');
$html2pdf->output('/tmp/html2pdf-justify-issue.pdf', 'F');

As far as I can tell the word spacing is set to 0 as the if condition fails here.

I hope this will help you solve this problem quickly.