Skip to content

Commit

Permalink
fix bug on div position spipu/html2pdf#73
Browse files Browse the repository at this point in the history
  • Loading branch information
aaryarajojuH committed Oct 19, 2022
1 parent 8248d9c commit 3265d31
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 20 additions & 9 deletions src/Html2Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 3265d31

Please sign in to comment.