diff --git a/src/Html2Pdf.php b/src/Html2Pdf.php index fb3c4b3f..94a9976a 100755 --- a/src/Html2Pdf.php +++ b/src/Html2Pdf.php @@ -578,7 +578,7 @@ public function output($name = 'document.pdf', $dest = 'I') // call the output of TCPDF $output = $this->pdf->Output($name, $dest); - + // close the pdf and clean up $this->clean(); @@ -3767,6 +3767,9 @@ protected function _tag_open_WRITE($param) $w = $this->parsingCss->value['width']; $align = 'R'; } + else if ($this->parsingCss->value['text-align'] === 'justify') { + $align = 'J'; + } // calculate the width of each words, and of all the sentence $w = 0; @@ -3833,7 +3836,7 @@ protected function _tag_open_WRITE($param) } if (strlen($str[0])) { - $this->pdf->SetXY($this->pdf->GetX(), $y+$dh+$dy); + $this->pdf->SetXY($this->pdf->GetX(), $y+$dh+$dy); $this->pdf->Cell($wc, $h, $str[0], 0, 0, $align, $fill, $this->_isInLink); $this->pdf->SetXY($this->pdf->GetX(), $y); } @@ -3907,6 +3910,7 @@ protected function _tag_open_WRITE($param) } // if we have words after automatic cut, it is because they fit on the line => we write the text + // if text should be justified, it will be left-aligned to avoid long spaces between words for shorter texts if (count($words)) { $txt = ''; foreach ($words as $k => $word) { @@ -3914,7 +3918,7 @@ protected function _tag_open_WRITE($param) } $w+= $this->pdf->getWordSpacing()*(count($words)); $this->pdf->SetXY($this->pdf->GetX(), $y+$dh+$dy); - $this->pdf->Cell(($align === 'L' ? $w : $this->parsingCss->value['width']), $h, $txt, 0, 0, $align, $fill, $this->_isInLink); + $this->pdf->Cell(($align === 'L' ? $w : $this->parsingCss->value['width']), $h, $txt, 0, 0, $align === 'J' ? 'L' : $align, $fill, $this->_isInLink); $this->pdf->SetXY($this->pdf->GetX(), $y); $this->_maxH = max($this->_maxH, $lh); $this->_maxE+= count($words);