Merge pull request #31442 from thersane-john/fix_v20_pdf_space_lost_with_images_eratosthene2

Fix DEVELOP pdf space lost with images eratosthene
This commit is contained in:
Laurent Destailleur 2024-12-09 01:10:01 +01:00 committed by GitHub
commit 13fba72d22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 306 additions and 247 deletions

View file

@ -223,6 +223,11 @@ abstract class CommonDocGenerator
*/
public $cols;
/**
* @var array<string,array{page:int,y:float|int}> Array of position data
*/
public $afterColsLinePositions;
/**
* @var array{fullpath:string} Array with result of doc generation. content is array('fullpath'=>$file)
*/
@ -1253,6 +1258,64 @@ abstract class CommonDocGenerator
}
}
/**
* Get position in PDF after col display
* @return false|array{page:int,y:float|int,col:string}
*/
public function getMaxAfterColsLinePositionsData()
{
if (empty($this->afterColsLinePositions) || !is_array($this->afterColsLinePositions)) {
return false;
}
$colId = '';
$maxPage = $maxY = 0;
foreach ($this->afterColsLinePositions as $colKey => $value) {
if ($value['page'] > $maxPage) {
$colId = $colKey;
$maxPage = $value['page'];
$maxY = $value['y']; // if page is higher we need to reset y to new max page y
} elseif ($value['page'] == $maxPage) {
$maxY = max($value['y'], $maxY);
$colId = $colKey;
}
}
return [
'col' => $colId,
'y' => $maxY,
'page' => $maxPage
];
}
/**
* Used for reset afterColsLinePositions var in start of a new pdf draw line loop
* @param float $y the new $y position usually get by TCPDF::GetY()
* @param int $pageNumb the page number to reset at
* @return void
*/
public function resetAfterColsLinePositionsData(float $y, int $pageNumb)
{
$this->afterColsLinePositions = [];
$this->setAfterColsLinePositionsData('startLine', $y, $pageNumb);
}
/**
* Used for to set afterColsLinePositions var in a pdf draw line loop
* @param string $colId the column id used as key in $this->cols or an unique id code like startLine or separateLine ....
* @param float $y the $y position usually get by TCPDF::GetY() where print data ended
* @param int $pageNumb the page number where print data ended
* @return void
*/
public function setAfterColsLinePositionsData(string $colId, float $y, int $pageNumb)
{
$this->afterColsLinePositions[$colId] = [
'page' => $pageNumb,
'y' => $y
];
}
/**
* uasort callback function to Sort columns fields
*
@ -1466,6 +1529,7 @@ abstract class CommonDocGenerator
// set cell padding with column content definition
$pdf->setCellPaddings(isset($colDef['content']['padding'][3]) ? $colDef['content']['padding'][3] : 0, isset($colDef['content']['padding'][0]) ? $colDef['content']['padding'][0] : 0, isset($colDef['content']['padding'][1]) ? $colDef['content']['padding'][1] : 0, isset($colDef['content']['padding'][2]) ? $colDef['content']['padding'][2] : 0);
$pdf->writeHTMLCell($colDef['width'], 2, isset($colDef['xStartPos']) ? $colDef['xStartPos'] : 0, $curY, $columnText, 0, 1, 0, true, $colDef['content']['align']);
$this->setAfterColsLinePositionsData($colKey, $pdf->GetY(), $pdf->getPage());
// restore cell padding
$pdf->setCellPaddings($curentCellPaddinds['L'], $curentCellPaddinds['T'], $curentCellPaddinds['R'], $curentCellPaddinds['B']);

View file

@ -200,10 +200,7 @@ class pdf_eratosthene extends ModelePDFCommandes
$nblines = (is_array($object->lines) ? count($object->lines) : 0);
$hidetop = 0;
if (getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE')) {
$hidetop = getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
}
$hidetop = getDolGlobalInt('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
// Loop on each lines to detect if there is at least one image to show
$realpatharray = array();
@ -366,6 +363,10 @@ class pdf_eratosthene extends ModelePDFCommandes
$tab_top = 90 + $top_shift + $shipp_shift;
$tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
if (!$hidetop && getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
// TODO : make this hidden conf the default behavior for each PDF when each PDF managed this new Display
$tab_top_newpage+= $this->tabTitleHeight;
}
$tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
@ -549,7 +550,24 @@ class pdf_eratosthene extends ModelePDFCommandes
$pageposbeforeprintlines = $pdf->getPage();
$pagenb = $pageposbeforeprintlines;
for ($i = 0; $i < $nblines; $i++) {
$linePosition = $i + 1;
$curY = $nexY;
// in First Check line page break and add page if needed
if (isset($object->lines[$i]->pagebreak) && $object->lines[$i]->pagebreak) {
// New page
$pdf->AddPage();
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
$pdf->setPage($pdf->getNumPages());
$nexY = $tab_top_newpage;
}
$this->resetAfterColsLinePositionsData($nexY, $pdf->getPage());
$pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
$pdf->SetTextColor(0, 0, 0);
@ -560,114 +578,76 @@ class pdf_eratosthene extends ModelePDFCommandes
}
$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.
$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
$pageposbefore = $pdf->getPage();
$curYBefore = $curY;
$showpricebeforepagebreak = 1;
// Allows data in the first page if description is long enough to break in multiples pages
$showpricebeforepagebreak = getDolGlobalInt('MAIN_PDF_DATA_ON_FIRST_PAGE');
$posYAfterImage = 0;
$posYAfterDescription = 0;
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
$imageTopMargin = 1;
if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imageTopMargin + $imglinesize['height']) > ($this->page_hauteur - $heightforfooter)) { // If photo too high, we moved completely on new page
$pdf->AddPage('', '', true);
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
$pdf->setPage($pageposbefore + 1);
$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
$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;
}
$showpricebeforepagebreak = 0;
}
// I remove the line commented below because it probably uselesss (or bug source) no need to change bottom margin because we have checked image fit
//$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($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + $imageTopMargin, $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'];
$this->setAfterColsLinePositionsData('photo', $posYAfterImage, $pdf->getPage());
}
}
// restore Page orientation for text
$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
// Description of product line
if ($this->getColumnStatus('desc')) {
$pdf->startTransaction();
$this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
$pageposafter = $pdf->getPage();
if ($pageposafter > $pageposbefore) { // There is a pagebreak
$pdf->rollbackTransaction(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.
$this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
$pageposafter = $pdf->getPage();
$posyafter = $pdf->GetY();
if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text
if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
$pdf->AddPage('', '', true);
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
$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();
$this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
}
$nexY = max($pdf->GetY(), $posYAfterImage);
$pageposafter = $pdf->getPage();
$afterPosData = $this->getMaxAfterColsLinePositionsData();
$pdf->setPage($pageposbefore);
$pdf->setTopMargin($this->marge_haute);
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
$pdf->setPageOrientation('', 0, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
// We suppose that a too long description or photo were moved completely on next page
if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
$pdf->setPage($pageposafter);
if ($afterPosData['page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
$pdf->setPage($afterPosData['page']);
$curY = $tab_top_newpage;
}
$pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
// # of line
// Line position
if ($this->getColumnStatus('position')) {
$this->printStdColumnContent($pdf, $curY, 'position', (string) ($i + 1));
$this->printStdColumnContent($pdf, $curY, 'position', strval($linePosition));
}
// VAT Rate
if ($this->getColumnStatus('vat')) {
$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
$nexY = max($pdf->GetY(), $nexY);
}
// Unit price before discount
if ($this->getColumnStatus('subprice')) {
$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
$nexY = max($pdf->GetY(), $nexY);
}
// Quantity
@ -675,7 +655,6 @@ class pdf_eratosthene extends ModelePDFCommandes
if ($this->getColumnStatus('qty')) {
$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'qty', $qty);
$nexY = max($pdf->GetY(), $nexY);
}
@ -683,28 +662,24 @@ class pdf_eratosthene extends ModelePDFCommandes
if ($this->getColumnStatus('unit')) {
$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'unit', $unit);
$nexY = max($pdf->GetY(), $nexY);
}
// Discount on line
if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
$remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
$nexY = max($pdf->GetY(), $nexY);
}
// Total excl tax line (HT)
if ($this->getColumnStatus('totalexcltax')) {
$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
$nexY = max($pdf->GetY(), $nexY);
}
// Total with tax line (TTC)
if ($this->getColumnStatus('totalincltax')) {
$total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
$nexY = max($pdf->GetY(), $nexY);
}
// Extrafields
@ -713,17 +688,18 @@ class pdf_eratosthene extends ModelePDFCommandes
if ($this->getColumnStatus($extrafieldColKey)) {
$extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
$this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
$nexY = max($pdf->GetY(), $nexY);
$this->setAfterColsLinePositionsData('options_'.$extrafieldColKey, $pdf->GetY(), $pdf->getPage());
}
}
}
$afterPosData = $this->getMaxAfterColsLinePositionsData();
$parameters = array(
'object' => $object,
'i' => $i,
'pdf' => & $pdf,
'curY' => & $curY,
'nexY' => & $nexY,
'nexY' => & $afterPosData['y'], // for backward module hook compatibility Y will be accessible by $object->getMaxAfterColsLinePositionsData()
'outputlangs' => $outputlangs,
'hidedetails' => $hidedetails
);
@ -785,60 +761,86 @@ class pdf_eratosthene extends ModelePDFCommandes
}
$this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate' => $vatrate, 'vatcode' => $vatcode, 'amount' => $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
$afterPosData = $this->getMaxAfterColsLinePositionsData();
$pdf->setPage($afterPosData['page']);
$nexY = $afterPosData['y'];
// Add line
if (getDolGlobalInt('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
$pdf->setPage($pageposafter);
if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData['y'] < $this->page_hauteur - $heightforfooter - 5) {
$pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
//$pdf->SetDrawColor(190,190,200);
$pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
$pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
$pdf->SetLineStyle(array('dash' => 0));
}
$nexY += 2; // Add space between lines
}
// Detect if some page were added automatically and output _tableau for past pages
while ($pagenb < $pageposafter) {
$pdf->setPage($pagenb);
if ($pagenb == $pageposbeforeprintlines) {
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
// Add last page for document footer if there are not enough size left
$afterPosData = $this->getMaxAfterColsLinePositionsData();
if ($afterPosData['y'] > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot) ) {
$pdf->AddPage();
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
$pagenb++;
$pdf->setPage($pagenb);
}
// Draw table frames and columns borders
$drawTabNumbPage = $pdf->getNumPages();
for ($i=$pageposbeforeprintlines; $i<=$drawTabNumbPage; $i++) {
$pdf->setPage($i);
// reset page orientation each loop to override it if it was changed
$pdf->setPageOrientation('', 0, 0); // The only function to edit the bottom margin of current page to set it.
$drawTabHideTop = $hidetop;
$drawTabTop = $tab_top_newpage;
$drawTabBottom = $this->page_hauteur - $heightforfooter;;
$hideBottom = 0; // TODO understand why it change to 1 or 0 during process
if ($i == $pageposbeforeprintlines) {
// first page need to start after notes
$drawTabTop = $tab_top;
} elseif (!$drawTabHideTop) {
if (getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
$drawTabTop-= $this->tabTitleHeight;
} else {
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
}
$this->_pagefoot($pdf, $object, $outputlangs, 1);
$pagenb++;
$pdf->setPage($pagenb);
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
$this->_pagehead($pdf, $object, 0, $outputlangs);
}
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
$drawTabHideTop = 1;
}
}
if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
if ($pagenb == $pageposafter) {
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
} else {
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
}
$this->_pagefoot($pdf, $object, $outputlangs, 1);
// New page
$pdf->AddPage();
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
$pagenb++;
if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
$this->_pagehead($pdf, $object, 0, $outputlangs);
}
// last page need to include document footer
if ($i == $pdf->getNumPages()) {
// remove document footer height to tab bottom position
$drawTabBottom-= $heightforfreetext + $heightforinfotot;
}
$drawTabHeight = $drawTabBottom - $drawTabTop;
$this->_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom, $object->multicurrency_code, $outputlangsbis);
$hideFreeText = $i != $pdf->getNumPages() ? 1 : 0; // Display free text only in last page
$this->_pagefoot($pdf, $object, $outputlangs, $hideFreeText);
$pdf->setPage($i); // in case of _pagefoot or _tableau change it
// reset page orientation each loop to override it if it was changed by _pagefoot or _tableau change it
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
// Don't print head on first page ($pageposbeforeprintlines) because already added previously
if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
$this->_pagehead($pdf, $object, 0, $outputlangs);
}
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
}
// Show square
if ($pagenb == $pageposbeforeprintlines) {
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
} else {
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
}
// reset text color before print footers
$pdf->SetTextColor(0, 0, 0);
$pdf->setPage($pdf->getNumPages());
$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
// Display infos area
@ -847,16 +849,8 @@ class pdf_eratosthene extends ModelePDFCommandes
// Display total zone
$posy = $this->drawTotalTable($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
// Display payment area
/*
if ($deja_regle)
{
$posy=$this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
}
*/
// Pagefoot
$this->_pagefoot($pdf, $object, $outputlangs);
// Add number of pages in footer
if (method_exists($pdf, 'AliasNbPages')) {
$pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
}

View file

@ -81,7 +81,6 @@ class pdf_cyan extends ModelePDFPropales
*/
public $cols;
/**
* Constructor
*
@ -194,10 +193,7 @@ class pdf_cyan extends ModelePDFPropales
$nblines = count($object->lines);
$hidetop = 0;
if (getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE')) {
$hidetop = getDolGlobalString('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
}
$hidetop = getDolGlobalInt('MAIN_PDF_DISABLE_COL_HEAD_TITLE');
// Loop on each lines to detect if there is at least one image to show
$realpatharray = array();
@ -361,6 +357,10 @@ class pdf_cyan extends ModelePDFPropales
$tab_top = 90 + $top_shift;
$tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
if (!$hidetop && getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
// TODO : make this hidden conf the default behavior for each PDF when each PDF managed this new Display
$tab_top_newpage+= $this->tabTitleHeight;
}
$nexY = $tab_top;
@ -558,8 +558,25 @@ class pdf_cyan extends ModelePDFPropales
// Loop on each lines
$pageposbeforeprintlines = $pdf->getPage();
$pagenb = $pageposbeforeprintlines;
for ($i = 0; $i < $nblines; $i++) {
$linePosition = $i + 1;
$curY = $nexY;
// in First Check line page break and add page if needed
if (isset($object->lines[$i]->pagebreak) && $object->lines[$i]->pagebreak) {
// New page
$pdf->AddPage();
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
$pdf->setPage($pdf->getNumPages());
$nexY = $tab_top_newpage;
}
$this->resetAfterColsLinePositionsData($nexY, $pdf->getPage());
$pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
$pdf->SetTextColor(0, 0, 0);
@ -570,112 +587,78 @@ class pdf_cyan extends ModelePDFPropales
}
$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.
$pdf->setPageOrientation('', 1, $heightforfooter); // 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('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
$imageTopMargin = 1;
if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imageTopMargin + $imglinesize['height']) > ($this->page_hauteur - $heightforfooter)) { // If photo too high, we moved completely on new page
$pdf->AddPage('', '', true);
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
$pdf->setPage($pageposbefore + 1);
$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
$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;
}
$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($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + $imageTopMargin, $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'];
$this->setAfterColsLinePositionsData('photo', $posYAfterImage, $pdf->getPage());
}
}
// Description of product line
// restore Page orientation for text
$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
if ($this->getColumnStatus('desc')) {
$pdf->startTransaction();
$this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
$pageposafter = $pdf->getPage();
if ($pageposafter > $pageposbefore) { // There is a pagebreak (not enough space for total+free text+footer)
$pdf->rollbackTransaction(true);
$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it to simple footer, so we can retry as if we have just the simple footer.
$this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
$pageposafter = $pdf->getPage();
$posyafter = $pdf->GetY();
//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) { // There is no space left for total+free text but no page break.
if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page manually because no break page was done automatically for the last part.
$pdf->AddPage('', '', true);
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
$pdf->setPage($pageposafter + 1);
}
} else {
// We found a page break that was done automatically and there is ow enough space for total+free text+footer.
// 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();
}
$posYAfterDescription = $pdf->GetY();
$this->setAfterColsLinePositionsData('desc', $pdf->GetY(), $pdf->getPage());
}
$nexY = $pdf->GetY();
$pageposafter = $pdf->getPage();
$afterPosData = $this->getMaxAfterColsLinePositionsData();
$pdf->setPage($pageposbefore);
$pdf->setTopMargin($this->marge_haute);
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
$curY = $curYBefore;
$pdf->setPageOrientation('', 0, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
// We suppose that a too long description or photo were moved completely on next page, so we set the value for $curY and current page that will be used by the following output.
if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
$pdf->setPage($pageposafter);
// We suppose that a too long description or photo were moved completely on next page
if ($afterPosData['page'] > $pageposbefore && (empty($showpricebeforepagebreak) || ($curY + 4) > ($this->page_hauteur - $heightforfooter))) {
$pdf->setPage($afterPosData['page']);
$curY = $tab_top_newpage;
}
$pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
// # of line
if ($this->getColumnStatus('position')) {
$this->printStdColumnContent($pdf, $curY, 'position', (string) ($i + 1));
$this->printStdColumnContent($pdf, $curY, 'position', strval($linePosition));
}
// VAT Rate
if ($this->getColumnStatus('vat')) {
$vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
$nexY = max($pdf->GetY(), $nexY);
}
// Unit price before discount
if ($this->getColumnStatus('subprice')) {
$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
$nexY = max($pdf->GetY(), $nexY);
}
// Quantity
@ -683,7 +666,6 @@ class pdf_cyan extends ModelePDFPropales
if ($this->getColumnStatus('qty')) {
$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'qty', $qty);
$nexY = max($pdf->GetY(), $nexY);
}
@ -691,28 +673,24 @@ class pdf_cyan extends ModelePDFPropales
if ($this->getColumnStatus('unit')) {
$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'unit', $unit);
$nexY = max($pdf->GetY(), $nexY);
}
// Discount on line
if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
$remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
$nexY = max($pdf->GetY(), $nexY);
}
// Total excl tax line (HT)
if ($this->getColumnStatus('totalexcltax')) {
$total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
$nexY = max($pdf->GetY(), $nexY);
}
// Total with tax line (TTC)
if ($this->getColumnStatus('totalincltax')) {
$total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
$this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
$nexY = max($pdf->GetY(), $nexY);
}
// Extrafields
@ -721,19 +699,21 @@ class pdf_cyan extends ModelePDFPropales
if ($this->getColumnStatus($extrafieldColKey)) {
$extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
$this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
$nexY = max($pdf->GetY(), $nexY);
$this->setAfterColsLinePositionsData('options_'.$extrafieldColKey, $pdf->GetY(), $pdf->getPage());
}
}
}
$afterPosData = $this->getMaxAfterColsLinePositionsData();
$parameters = array(
'object' => $object,
'i' => $i,
'pdf' => & $pdf,
'curY' => & $curY,
'nexY' => & $nexY,
'outputlangs' => $outputlangs,
'hidedetails' => $hidedetails
'object' => $object,
'i' => $i,
'pdf' => & $pdf,
'curY' => & $curY,
'nexY' => & $afterPosData['y'], // for backward module hook compatibility Y will be accessible by $object->getMaxAfterColsLinePositionsData()
'outputlangs' => $outputlangs,
'hidedetails' => $hidedetails
);
$reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
@ -804,13 +784,14 @@ class pdf_cyan extends ModelePDFPropales
}
$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);
}
$afterPosData = $this->getMaxAfterColsLinePositionsData();
$pdf->setPage($afterPosData['page']);
$nexY = $afterPosData['y'];
// Add line
if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
$pdf->setPage($pageposafter);
if (getDolGlobalString('MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1) && $afterPosData['y'] < $this->page_hauteur - $heightforfooter - 5) {
$pdf->SetLineStyle(array('dash' => '1,1', 'color' => array(80, 80, 80)));
//$pdf->SetDrawColor(190,190,200);
$pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
@ -818,54 +799,75 @@ class pdf_cyan extends ModelePDFPropales
}
$nexY += 2; // Add space between lines
}
// Detect if some page were added automatically and output _tableau for past pages
while ($pagenb < $pageposafter) {
$pdf->setPage($pagenb);
if ($pagenb == $pageposbeforeprintlines) {
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
// Add last page for document footer if there are not enough size left
$afterPosData = $this->getMaxAfterColsLinePositionsData();
if ($afterPosData['y'] > $this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot) ) {
$pdf->AddPage();
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
$pagenb++;
$pdf->setPage($pagenb);
}
// Draw table frames and columns borders
$drawTabNumbPage = $pdf->getNumPages();
for ($i=$pageposbeforeprintlines; $i<=$drawTabNumbPage; $i++) {
$pdf->setPage($i);
// reset page orientation each loop to override it if it was changed
$pdf->setPageOrientation('', 0, 0); // The only function to edit the bottom margin of current page to set it.
$drawTabHideTop = $hidetop;
$drawTabTop = $tab_top_newpage;
$drawTabBottom = $this->page_hauteur - $heightforfooter;;
$hideBottom = 0; // TODO understand why it change to 1 or 0 during process
if ($i == $pageposbeforeprintlines) {
// first page need to start after notes
$drawTabTop = $tab_top;
} elseif (!$drawTabHideTop) {
if (getDolGlobalInt('MAIN_PDF_ENABLE_COL_HEAD_TITLE_REPEAT')) {
$drawTabTop-= $this->tabTitleHeight;
} else {
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
}
$this->_pagefoot($pdf, $object, $outputlangs, 1);
$pagenb++;
$pdf->setPage($pagenb);
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
$this->_pagehead($pdf, $object, 0, $outputlangs);
}
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
$drawTabHideTop = 1;
}
}
if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { // @phan-suppress-current-line PhanUndeclaredProperty
if ($pagenb == $pageposafter) {
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
} else {
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
}
$this->_pagefoot($pdf, $object, $outputlangs, 1);
// New page
$pdf->AddPage();
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
$pagenb++;
if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) {
$this->_pagehead($pdf, $object, 0, $outputlangs);
}
// last page need to include document footer
if ($i == $pdf->getNumPages()) {
// remove document footer height to tab bottom position
$drawTabBottom-= $heightforsignature + $heightforfreetext + $heightforinfotot;
}
$drawTabHeight = $drawTabBottom - $drawTabTop;
$this->_tableau($pdf, $drawTabTop, $drawTabHeight, 0, $outputlangs, $drawTabHideTop, $hideBottom, $object->multicurrency_code, $outputlangsbis);
$hideFreeText = $i != $pdf->getNumPages() ? 1 : 0; // Display free text only in last page
$this->_pagefoot($pdf, $object, $outputlangs, $hideFreeText);
$pdf->setPage($i); // in case of _pagefoot or _tableau change it
// reset page orientation each loop to override it if it was changed by _pagefoot or _tableau change it
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
// Don't print head on first page ($pageposbeforeprintlines) because already added previously
if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') && $i != $pageposbeforeprintlines) {
$this->_pagehead($pdf, $object, 0, $outputlangs);
}
if (!empty($tplidx)) {
$pdf->useTemplate($tplidx);
}
}
// Show square
if ($pagenb == $pageposbeforeprintlines) {
$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
} else {
$this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
}
// reset text color before print footers
$pdf->SetTextColor(0, 0, 0);
$pdf->setPage($pdf->getNumPages());
$bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
// Display infos area
$posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
@ -878,8 +880,7 @@ class pdf_cyan extends ModelePDFPropales
$posy = $this->drawSignatureArea($pdf, $object, $posy, $outputlangs);
}
// Pagefoot
$this->_pagefoot($pdf, $object, $outputlangs);
// Add number of pages in footer
if (method_exists($pdf, 'AliasNbPages')) {
$pdf->AliasNbPages(); // @phan-suppress-current-line PhanUndeclaredMethod
}