Produkt Template Seitenumbruch funktioniert nicht

Hallo liebe Community,

Web-Hosting - Version 18.0.0

ich habe für unsere Firma ein Produkt-Template zusammengebaut um einen Aufkleber je bestelltem Produkt zu generieren.
Dazu verwende ich das Liefer-Modul und erzeuge aus den einzelnen Positionen ein Klebe-Etikette.

Das Template ist soweit fertig und es funktioniert das Etikette auf der Seite 1 aber ab der Seite 2 werden immer 2 Produkte übereinander gelegt.

Falls da jemand helfen kann würde ich den Code posten, bzw. per Mail verschicken.

Abschließend hätte ich noch einen Spezialisten für Extrafelder benötigt, da diese auf der PDF nicht angedruckt werden und ich hab schon Tage ohne Erfolg verbracht.

Danke für Eure Unterstützung.

LG Günter

Hi @OnkelSepp04,

ohne Code ist es schwierig zu sagen was nicht stimmt. Ich würde aber vielleicht erstmal auf einer Testumgebung auf die aktuellste Version 18.0.x gehen um auszuschließen, dass es durch einen Bug der schon bekannt und in vorherigen Versionen gefixt wurde und dann nochmal prüfen. Wenn es immer noch nicht geht, dann vielleicht den Code posten.

Viele Grüße
Sven

Hallo Sven,

leider hat der Test am DoliWamp Server (Version 18.0.3) auch kein anderes Ergebnis gebracht.
Anbei der Code, welchen ich bis jetzt verwende - bei 2 - 3 Produkten funktioniert der Code einwandfrei ab dem 4 Produkt werden auf der 3. Seite zwei Produkte übereinander gedruckt und so geht es weiter.

+++++ CODE +++++

require_once DOL_DOCUMENT_ROOT.‚/core/modules/expedition/modules_expedition.php‘;
require_once DOL_DOCUMENT_ROOT.‚/core/class/extrafields.class.php‘;
require_once DOL_DOCUMENT_ROOT.‚/contact/class/contact.class.php‘;
require_once DOL_DOCUMENT_ROOT.‚/core/lib/company.lib.php‘;
require_once DOL_DOCUMENT_ROOT.‚/core/lib/pdf.lib.php‘;

/**

  • Class to build sending documents with model Label
    /
    class pdf_label extends ModelePdfExpedition
    {
    /
    *

    • @var DoliDb Database handler
      */
      public $db;

    /**

    • @var string model name
      */
      public $name;

    /**

    • @var string model description (short text)
      */
      public $description;

    /**

    • @var int Save the name of generated file as the main doc when generating a doc with this template
      */
      public $update_main_doc_field;

    /**

    • @var string document type
      */
      public $type;

    /**

    • Dolibarr version of the loaded document
    • @var string
      */
      public $version = ‚dolibarr‘;

    /**

    • @var int page_largeur
      */
      public $page_largeur;

    /**

    • @var int page_hauteur
      */
      public $page_hauteur;

    /**

    • @var array format
      */
      public $format;

    /**

    • @var int marge_gauche
      */
      public $marge_gauche;

    /**

    • @var int marge_droite
      */
      public $marge_droite;

    /**

    • @var int marge_haute
      */
      public $marge_haute;

    /**

    • @var int marge_basse
      */
      public $marge_basse;

    /**

    • Issuer
    • @var Societe
      */
      public $emetteur;

    /**

    • Constructor

    • @param DoliDB $db Database handler
      */
      public function __construct(DoliDB $db)
      {
      global $conf, $langs, $mysoc;

      $this->db = $db;
      $this->name = „label“;
      $this->description = $langs->trans(„DocumentModelLabel“);
      $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template

      $this->type = ‚pdf‘;
      $formatarray = pdf_getFormat();
      $this->page_largeur = 62;
      $this->page_hauteur = 60;
      $this->format = array($this->page_largeur, $this->page_hauteur);
      $this->option_logo = 1; // Display logo

      // Get source company
      $this->emetteur = $mysoc;
      if (!$this->emetteur->country_code) {
      $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined
      }
      }

    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
    /**

    • Function to build pdf onto disk

    • @param Expedition $object Object expedition to generate (or id if old method)

    • @param Translate $outputlangs Lang output object

    • @param string $srctemplatepath Full path of source filename for generator using a template file

    • @param int $hidedetails Do not show line details

    • @param int $hidedesc Do not show desc

    • @param int $hideref Do not show ref

    • @return int 1=OK, 0=KO
      */
      public function write_file(&$object, $outputlangs, $srctemplatepath = ‚‘, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
      {

      //********* Code für Extrafeld *********
      $extrafields = new extraFields($db);
      $extralabels=$extrafields->fetch_name_optionals_label($object->table_llx_product_extrafields);
      $object->fetch($rowid);
      $object->fetch_optionals($rowid,$extralabels);
      print $object->array_options [‚options_artgr‘];
      //********* Code Ende *********

      // phpcs:enable
      global $user, $conf, $langs, $mysoc, $hookmanager;

      if (!is_object($outputlangs)) {
      $outputlangs = $langs;
      }
      // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
      if (!empty($conf->global->MAIN_USE_FPDF)) {
      $outputlangs->charset_output = ‚ISO-8859-1‘;
      }

      // Load traductions files required by page
      $outputlangs->loadLangs(array(„main“, „bills“, „products“, „dict“, „companies“, „propal“, „deliveries“, „sendings“, „productbatch“));

      if ($conf->expedition->dir_output) {
      $object->fetch_thirdparty();

      $origin = $object->origin;
      
      //Create sender
      $this->expediteur = $mysoc;
      
      // Definition of $dir and $file
      if ($object->specimen) {
      	$dir = $conf->expedition->dir_output."/sending";
      	$file = $dir."/SPECIMEN.pdf";
      } else {
      	$expref = dol_sanitizeFileName($object->ref);
      	$dir = $conf->expedition->dir_output."/sending/".$expref;
      	$file = $dir."/".$expref.".pdf";
      }
      
      if (!file_exists($dir)) {
      	if (dol_mkdir($dir) < 0) {
      		$this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
      		return 0;
      	}
      }
      
      if (file_exists($dir)) {
      	// Add pdfgeneration hook
      	if (!is_object($hookmanager)) {
      		include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
      		$hookmanager = new HookManager($this->db);
      	}
      	$hookmanager->initHooks(array('pdfgeneration'));
      	$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
      	global $action;
      	$reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
      
      	$nblines = count($object->lines);
      
      	$pdf = pdf_getInstance($this->format, 'mm', 'l');
      	$default_font_size = pdf_getPDFFontSize($outputlangs);
      	$heightforinfotot = 0; // Height reserved to output the info and total part
      	$heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
      	if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS)) {
      		$heightforfooter += 56;
      	}
      	$pdf->SetAutoPageBreak(1, 0);
      
          if (class_exists('TCPDF')) {
      		$pdf->setPrintHeader(false);
      		$pdf->setPrintFooter(false);
      	}
      	//$pdf->SetFont(pdf_getPDFFont($outputlangs));
      
      	// Set path to the background PDF File
      	if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
      		$pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
      		$tplidx = $pdf->importPage(1);
      	}
      
      	$pdf->Open();
      	$pagenb = 0;
      	$pdf->SetDrawColor(128, 128, 128);
      
      	if (method_exists($pdf, 'AliasNbPages')) {
      		$pdf->AliasNbPages();
      	}
      
      	$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
      	//$pdf->SetSubject($outputlangs->transnoentities("Shipment"));
      	$pdf->SetCreator("Dolibarr ".DOL_VERSION);
      	$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
      	$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment"));
      	if (getDolGlobalString('MAIN_DISABLE_PDF_COMPRESSION')) {
      		$pdf->SetCompression(false);
      	}
      
      	// New page
      	$pdf->AddPage();
      	$pagenb++;
      	$this->_pagehead($pdf, $object, 1, $outputlangs);
      	$pdf->SetFont('', '', $default_font_size - 3);
      	$pdf->MultiCell(0, 3, ''); // Set interline to 3
      	$pdf->SetTextColor(0, 0, 0);
      
      	$tab_top = 2;
      	$tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 1 : 10);
      
      	$pdf->SetFillColor(240, 240, 240);
      	$pdf->SetTextColor(0, 0, 0);
      	$pdf->SetXY(2, 2);
      
      	$num = count($object->lines);
      
      	// Loop on each lines
      	for ($i = 0; $i < $num; $i++) {
      		$curY = $nexY;
      		$pdf->SetFont('', '', $default_font_size - 3);
      		$pdf->SetTextColor(0, 0, 0);
      
      		$pdf->setTopMargin($tab_top_newpage);
      		$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
      		$pageposbefore = $pdf->getPage();
      
      		// Description of product line
      		//$libelleproduitservice = pdf_writelinedesc($pdf, $object, $i, $outputlangs, 90, 3, 5, $curY, 0, 1);
              //$pdf->MultiCell(30, 3, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'L', 0);
              
      		$nexY = $pdf->GetY();
      		$pageposafter = $pdf->getPage();
      		$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.
      
      		// We suppose that a too long description is moved completely on next page
      		if ($pageposafter > $pageposbefore) {
      			$pdf->setPage($pageposafter);
      			$curY = $tab_top_newpage;
      		}	
      
      		//Inserting the product reference
      		//$pdf->SetXY(10, $curY + 48);
      		//$pdf->SetFont('', '', $default_font_size - 6);
      		//$pdf->MultiCell(50, 5, $outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'R', 0);
      
              //$pdf->SetXY(2, $curY - 28);
              //$pdf->SetFont('', '', $default_font_size - 5);
              //$pdf->MultiCell($this->page_largeur - 4, 0, $outputlangs->transnoentities("Art.-Nr.").': '.$outputlangs->convToOutputCharset($object->lines[$i]->ref), 1, 'R', 0);                
          	
              $pdf->SetXY(2, 17);
              $pdf->SetFont('', 'B', $default_font_size + 5);
      		$pdf->MultiCell(58, 3, $outputlangs->transnoentities("DIN 933"), 0, 'R', 0);
      
              $pdf->SetFont('', 'B', $default_font_size + 5);
              $pdf->SetXY(2, 25);
      		$pdf->MultiCell(40, 3, $outputlangs->transnoentities("M8x60"), 0, 'L', 0);
              
              $pdf->SetXY(2, 28);
              $pdf->SetFont('', 'B', $default_font_size - 3);
      		$pdf->MultiCell(58, 3, $object->lines[$i]->qty_asked.' '.$outputlangs->transnoentities("Stück "), 0, 'R', 0);
      
              $pdf->SetXY(2, 32);
              $pdf->SetFont('', '', $default_font_size - 5);
              $pdf->MultiCell(58, 3, $outputlangs->transnoentities("Art.-Nr.").': '.$outputlangs->convToOutputCharset($object->lines[$i]->ref), 0, 'R', 0);
      
              $pdf->SetFont('', ' ', $default_font_size - 2);
              $pdf->SetXY(2, 35);
      		$pdf->MultiCell(40, 3, $outputlangs->transnoentities("Sechskantschraube"), 0, 'L', 0);
      
              $pdf->SetFont('', 'B', $default_font_size - 2);
              $pdf->SetXY(2, 40);
      		$pdf->MultiCell(40, 3, $outputlangs->transnoentities("verzinkt blau     8.8"), 0, 'L', 0);
      
              $pdf->SetXY(2, 45);
              $pdf->SetFont('', '', $default_font_size - 6);
              $pdf->MultiCell($this->page_largeur - 4, 3, $outputlangs->transnoentities("Lot Nr.").': '.$outputlangs->convToOutputCharset($object->ref), '', 'L');         
      
              $pdf->MultiCell (0,$this->page_hauteur - 4, $outputlangs->transnoentities("Art-Gr.").': '.$outputlangs->convToOutputCharset($object->array_options ['artgr']),0,'L');
              //$pdf->MultiCell($this->page_largeur - 4, 3, $outputlangs->convToOutputCharset($object->artgr), '', 'L');      
              //$pdf->writeHTMLCell (190,3, $pdf->getX(), $curY + 10, $andereVariable,0,1); // NEUE ZEILE  				
              
      
              //$pdf->MultiCell($this->page_largeur - 4, $this->page_hauteur, $outputlangs->convToOutputCharset($object->lines[$i]->array_options['options_artgr']),0,'L');
      
              
      		// Detect if some page were added automatically and output _tableau for past pages
      		while ($pagenb < $pageposafter) {
      			$pdf->setPage($pagenb);
      			if ($pagenb == 1) {
      				$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
      			} else {
      				$this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
      			}
      			$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 (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
      			if ($pagenb == 1) {
      				$this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
      			} else {
      				$this->_tableau($pdf, $tab_top_newpage - 1, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
      			}
      			$this->_pagefoot($pdf, $object, $outputlangs, 1);
      			// New page
      			$pdf->AddPage();
      			$pagenb++;
      		}
      	}
      
      	// Pagefoot
      	$this->_pagefoot($pdf, $object, $outputlangs);
      	if (method_exists($pdf, 'AliasNbPages')) {
      		$pdf->AliasNbPages();
      	}
      
      	$pdf->Close();
      
      	$pdf->Output($file, 'F');
      
      	// Add pdfgeneration hook
      	if (!is_object($hookmanager)) {
      		include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
      		$hookmanager = new HookManager($this->db);
      	}
      	$hookmanager->initHooks(array('pdfgeneration'));
      	$parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
      	global $action;
      	$reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
      	if ($reshook < 0) {
      		$this->error = $hookmanager->error;
      		$this->errors = $hookmanager->errors;
      	}
      
      	dolChmod($file);
      
      	$this->result = array('fullpath'=>$file);
      
      	return 1;
      } else {
      	$this->error = $outputlangs->transnoentities("ErrorCanNotCreateDir", $dir);
      	return 0;
      }
      

      } else {
      $this->error = $outputlangs->transnoentities(„ErrorConstantNotDefined“, „EXP_OUTPUTDIR“);
      return 0;
      }
      }

    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
    /**

    • Show table for lines
    • @param TCPDF $pdf Object PDF
    • @param string $tab_top Top position of table
    • @param string $tab_height Height of table (rectangle)
    • @param int $nexY Y
    • @param Translate $outputlangs Langs object
    • @param int $hidetop Hide top bar of array
    • @param int $hidebottom Hide bottom bar of array
    • @return void
      */
      protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0)
      {
      global $langs;
      $default_font_size = pdf_getPDFFontSize($outputlangs);
    // Translations
    $langs->loadLangs(array("main", "bills", "orders")); 
    

    }

    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
    /**

    •  Show footer of page. Need this->emetteur object
      
    •  @param	TCPDF		$pdf     			PDF
      
    •  @param	Expedition	$object				Object to show
      
    •  @param	Translate	$outputlangs		Object lang for output
      
    •  @param	int			$hidefreetext		1=Hide free text
      
    •  @return	void
      

    */
    protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
    {
    // Add background image
    $pdf->Image(DOL_DOCUMENT_ROOT.‚/core/modules/expedition/doc/WIMAXX_Logo.png‘, 1, 2, 30, 6.5);
    $pdf->Image(DOL_DOCUMENT_ROOT.‚/core/modules/expedition/doc/favicon.png‘, 50, 2, 8, 8);

    $default_font_size = pdf_getPDFFontSize($outputlangs);
    $pdf->SetFont('', 'B', $default_font_size - 1);
    $pdf->SetXY($posx + 2, $posy - 7);
    $pdf->MultiCell(60, 3, $outputlangs->transnoentities("www.wimaxx.at"), 0, 'L');
    $pdf->SetXY($posx, $posy + 50);
    $pdf->SetFillColor(255, 0, 0);
    $pdf->MultiCell(62, 10, " ", 0, 'L', 1);
    $pdf->SetXY($posx, $posy + 15);
    $pdf->SetFillColor(124, 124, 124);
    $pdf->MultiCell(62, 10, " ", 0, 'L', 1);
    
    //*********************SLOGAN****************************
    $pdf->SetXY($posx + 1.5, $posy + 8);
    $pdf->SetFont('', 'B', $default_font_size - 3);
    $pdf->SetTextColor(0, 0, 0);
    $pdf->MultiCell(56, 3, $outputlangs->transnoentities("BEWEGT.WIRKT.HÄLT"), '', 'L');
    

    }

    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
    /**

    • Show top header of page.

    • @param TCPDF $pdf Object PDF

    • @param Expedition $object Object to show

    • @param int $showaddress 0=no, 1=yes

    • @param Translate $outputlangs Object lang for output

    • @return int <0 if KO, > if OK
      */
      protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
      {
      global $conf, $langs, $hookmanager;

      $default_font_size = pdf_getPDFFontSize($outputlangs);

      // Load traductions files required by page
      $outputlangs->loadLangs(array(„main“, „bills“, „propal“, „companies“));

      $default_font_size = pdf_getPDFFontSize($outputlangs);

      pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);

      // Add background image
      //$pdf->Image(DOL_DOCUMENT_ROOT.‚/core/modules/expedition/doc/Etikette_blanko.png‘, 0, 0, 100, 70);

      //Affiche le filigrane brouillon - Print Draft Watermark
      if ($object->statut == 0 && (!empty($conf->global->SENDING_DRAFT_WATERMARK))) {
      pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, ‚mm‘, $conf->global->SENDING_DRAFT_WATERMARK);
      }
      }
      }

Das Extrafeld funktionieren auch noch (artgr) nicht aber das sollte erst das zweite Problem sein.

Danke für jegliche Idee

LG Günther