Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX : v20 pdf space lost with images eratosthene #31298

Open
wants to merge 3 commits into
base: 20.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 56 additions & 19 deletions htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,43 +551,59 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
$pdf->setTopMargin($tab_top_newpage);
$pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
$pageposbefore = $pdf->getPage();
$curYBefore = $curY;

// Allows data in the first page if description is long enough to break in multiples pages
$showpricebeforepagebreak = getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE');
if ($curYBefore > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 5))) {
// disable MAIN_PDF_DATA_ON_FIRST_PAGE near page break limit to anticipate auto page break jump before add line due to padding
// (ex: description is on page 2 and price on page 1)
$showpricebeforepagebreak = 0;
}


$showpricebeforepagebreak = 1;
$posYAfterImage = 0;
$posYAfterDescription = 0;

if ($this->getColumnStatus('position')) {
$this->printStdColumnContent($pdf, $curY, 'position', $i + 1);
}

$newPageAddedForPhoto = false;
if ($this->getColumnStatus('photo')) {
// We start with Photo of product line
if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // If photo too high, we moved completely on new page
if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext))) { // If photo too high, we moved completely on new page
$pdf->AddPage('', '', true);
$newPageAddedForPhoto = true;
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
$pdf->setPage($pageposbefore + 1);

$curY = $tab_top_newpage;

// Allows data in the first page if description is long enough to break in multiples pages
if (getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
$showpricebeforepagebreak = 1;
} else {
$showpricebeforepagebreak = 0;
}
// disable MAIN_PDF_DATA_ON_FIRST_PAGE near page break limit to anticipate auto page break jump before add line due to padding
// (ex: description is on page 2 and price on page 1)
$showpricebeforepagebreak = 0;
}

$pdf->setPageOrientation('', 0, $heightforfooter + $heightforfreetext); // The only function to edit the bottom margin of current page to set it.
if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
$pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + 1, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
// $pdf->Image does not increase value return by getY, so we save it manually
$posYAfterImage = $curY + $imglinesize['height'];
}

$pageposafter = $pdf->getPage();
if ($pageposafter > $pageposbefore) { // There is a pagebreak
$pdf->setPage($pageposbefore+1);
}

// restore page bottom margin
$pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
}

// Description of product line
$newPageAddedForDescription = false;
if ($this->getColumnStatus('desc')) {
$pdf->startTransaction();

Expand All @@ -596,6 +612,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede

if ($pageposafter > $pageposbefore) { // There is a pagebreak
$pdf->rollbackTransaction(true);
$newPageAddedForDescription = true;
$pageposafter = $pageposbefore;
//print $pageposafter.'-'.$pageposbefore;exit;
$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
Expand All @@ -611,23 +628,19 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
}
$pdf->setPage($pageposafter + 1);
}
} else {
// We found a page break
// Allows data in the first page if description is long enough to break in multiples pages
if (getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
$showpricebeforepagebreak = 1;
} else {
$showpricebeforepagebreak = 0;
}
}
} else { // No pagebreak
$pdf->commitTransaction();
}
$posYAfterDescription = $pdf->GetY();
}

$nexY = $pdf->GetY();

$nexY = max($pdf->GetY(), $posYAfterImage);
// check if image height is more than description height
if (!$newPageAddedForPhoto && $posYAfterImage) {
$nexY = max($posYAfterImage, $nexY);
}


$pageposafter = $pdf->getPage();
Expand All @@ -640,6 +653,8 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
$pdf->setPage($pageposafter);
$curY = $tab_top_newpage;
} else {
$curY = $curYBefore;
}

$pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
Expand Down Expand Up @@ -773,8 +788,30 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
}
$this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);


// if new pages have been added, we need to check whether they were created by the image display script or the description display script
if ($pageposafter > $pageposbefore && !empty($showpricebeforepagebreak)) {
$pdf->setPage($pageposafter);

if ($pageposafter - $pageposbefore > 2 && $newPageAddedForDescription) {
// photo can't add 2 pages, so it must be description who break others pages
$nexY = $posYAfterDescription;
} elseif ($newPageAddedForPhoto && $newPageAddedForDescription) {
// if break page is detect for photo and description we need to take the bigger Y
$nexY = max($posYAfterImage, $posYAfterDescription);
} elseif ($newPageAddedForPhoto) {
$nexY = $posYAfterImage;
} else {
$nexY = $posYAfterDescription;
}
}


// Add line
if (getDolGlobalInt('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
if (getDolGlobalInt('MAIN_PDF_DASH_BETWEEN_LINES')
&& $i < ($nblines - 1)
&& ($nexY < $this->page_hauteur - ($heightforfooter + $heightforfreetext + 1)) // do not draw line because already done by array frame
) {
$pdf->setPage($pageposafter);
$pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
//$pdf->SetDrawColor(190,190,200);
Expand Down
65 changes: 45 additions & 20 deletions htdocs/core/modules/propale/doc/pdf_cyan.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,43 +563,53 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
$pdf->setTopMargin($tab_top_newpage);
$pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
$pageposbefore = $pdf->getPage();
$curYBefore = $curY;

// Allows data in the first page if description is long enough to break in multiples pages
$showpricebeforepagebreak = getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE');

$showpricebeforepagebreak = 1;
$posYAfterImage = 0;
$posYAfterDescription = 0;

if ($this->getColumnStatus('position')) {
$this->printStdColumnContent($pdf, $curY, 'position', $i + 1);
}

$newPageAddedForPhoto = false;
if ($this->getColumnStatus('photo')) {
// We start with Photo of product line
if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) { // If photo too high, we moved completely on new page
if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext))) { // If photo too high, we moved completely on new page
$pdf->AddPage('', '', true);
$newPageAddedForPhoto = true;
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
$pdf->setPage($pageposbefore + 1);

$curY = $tab_top_newpage;

// Allows data in the first page if description is long enough to break in multiples pages
if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
$showpricebeforepagebreak = 1;
} else {
$showpricebeforepagebreak = 0;
}
// disable MAIN_PDF_DATA_ON_FIRST_PAGE near page break limit to anticipate auto page break jump before add line due to padding
// (ex: description is on page 2 and price on page 1)
$showpricebeforepagebreak = 0;
}


$pdf->setPageOrientation('', 0, $heightforfooter + $heightforfreetext); // The only function to edit the bottom margin of current page to set it.
if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
$pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + 1, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
// $pdf->Image does not increase value return by getY, so we save it manually
$posYAfterImage = $curY + $imglinesize['height'];
}

$pageposafter = $pdf->getPage();
if ($pageposafter > $pageposbefore) { // There is a pagebreak
$pdf->setPage($pageposbefore+1);
}

// restore page bottom margin
$pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
}

// Description of product line
$newPageAddedForDescription = false;
if ($this->getColumnStatus('desc')) {
$pdf->startTransaction();

Expand All @@ -608,6 +618,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede

if ($pageposafter > $pageposbefore) { // There is a pagebreak
$pdf->rollbackTransaction(true);
$newPageAddedForDescription = true;

$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.

Expand All @@ -624,14 +635,6 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
}
$pdf->setPage($pageposafter + 1);
}
} else {
// We found a page break
// Allows data in the first page if description is long enough to break in multiples pages
if (getDolGlobalString('MAIN_PDF_DATA_ON_FIRST_PAGE')) {
$showpricebeforepagebreak = 1;
} else {
$showpricebeforepagebreak = 0;
}
}
} else { // No pagebreak
$pdf->commitTransaction();
Expand All @@ -640,6 +643,12 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
}

$nexY = $pdf->GetY();

// check if image height is more than description height
if (!$newPageAddedForPhoto && $posYAfterImage) {
$nexY = max($posYAfterImage, $nexY);
}

$pageposafter = $pdf->getPage();

$pdf->setPage($pageposbefore);
Expand All @@ -650,6 +659,8 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
$pdf->setPage($pageposafter);
$curY = $tab_top_newpage;
} else {
$curY = $curYBefore;
}

$pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
Expand Down Expand Up @@ -794,8 +805,22 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede
}
$this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);

if ($posYAfterImage > $posYAfterDescription) {
$nexY = max($nexY, $posYAfterImage);

// if new pages have been added, we need to check whether they were created by the image display script or the description display script
if ($pageposafter > $pageposbefore && !empty($showpricebeforepagebreak)) {
$pdf->setPage($pageposafter);

if ($pageposafter - $pageposbefore > 2 && $newPageAddedForDescription) {
// photo can't add 2 pages, so it must be description who break others pages
$nexY = $posYAfterDescription;
} elseif ($newPageAddedForPhoto && $newPageAddedForDescription) {
// if break page is detect for photo and description we need to take the bigger Y
$nexY = max($posYAfterImage, $posYAfterDescription);
} elseif ($newPageAddedForPhoto) {
$nexY = $posYAfterImage;
} else {
$nexY = $posYAfterDescription;
}
}

// Add line
Expand Down
Loading