From 3265d31cf66e46c1d99c71b44ece59ef69bf5ab0 Mon Sep 17 00:00:00 2001 From: aaryarajojuH Date: Wed, 19 Oct 2022 08:08:59 +0800 Subject: [PATCH] fix bug on div position https://github.com/spipu/html2pdf/issues/73 --- CHANGELOG.md | 1 + src/Html2Pdf.php | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d62b9bf..b7edc19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file. * fix a infinite loop case when reading a svg path * fix issue from https://github.com/spipu/html2pdf/pull/177 * fix issue from https://github.com/spipu/html2pdf/pull/163 + * fix bug on div position https://github.com/spipu/html2pdf/issues/73 ## [4.6.0] - 2016-03-30 diff --git a/src/Html2Pdf.php b/src/Html2Pdf.php index 0c01b97..204e7b1 100755 --- a/src/Html2Pdf.php +++ b/src/Html2Pdf.php @@ -3167,8 +3167,8 @@ protected function _tag_open_DIV($param, $other = 'div') $overW = null; $overH = null; $overflow = false; - $this->parsingCss->value['width'] = max($w, $this->parsingCss->value['width']); - $this->parsingCss->value['height'] = max($h, $this->parsingCss->value['height']); + $this->parsingCss->value['width'] = max($w, $this->parsingCss->value['width']); + $this->parsingCss->value['height'] = max($h, $this->parsingCss->value['height']); } switch ($this->parsingCss->value['rotate']) { @@ -3215,17 +3215,28 @@ protected function _tag_open_DIV($param, $other = 'div') break; } + $maxW = ($this->pdf->getW() - $this->pdf->getlMargin()-$this->pdf->getrMargin()); + $maxH = ($this->pdf->getH() - $this->pdf->gettMargin()-$this->pdf->getbMargin()); + $maxX = ($this->pdf->getW() - $this->pdf->getrMargin()); + $maxY = ($this->pdf->getH() - $this->pdf->getbMargin()); + $endX = ($this->pdf->getX() + $w); + $endY = ($this->pdf->getY() + $h); + + $w = round($w, 6); + $h = round($h, 6); + $maxW = round($maxW, 6); + $maxH = round($maxH, 6); + $maxX = round($maxX, 6); + $maxY = round($maxY, 6); + $endX = round($endX, 6); + $endY = round($endY, 6); + if (!$this->parsingCss->value['position']) { - if ($w < ($this->pdf->getW() - $this->pdf->getlMargin()-$this->pdf->getrMargin()) && - $this->pdf->getX() + $w>=($this->pdf->getW() - $this->pdf->getrMargin()) - ) { + if ($w < $maxW && $endX >= $maxX) { $this->_tag_open_BR(array()); } - if (($h < ($this->pdf->getH() - $this->pdf->gettMargin()-$this->pdf->getbMargin())) && - ($this->pdf->getY() + $h>=($this->pdf->getH() - $this->pdf->getbMargin())) && - !$this->_isInOverflow - ) { + if ($h < $maxH && $endY >= $maxY && !$this->_isInOverflow) { $this->_setNewPage(); }