TCPDF: en algún momento agregue una nueva página y luego se desborda el contenido de la siguiente página

Tengo que crear un pdf con el uso de la biblioteca tcpdf. Estoy enfrentando un problema relacionado con el desbordamiento de contenido en la página siguiente. en algún momento agregue una nueva página y el contenido de la siguiente página se desbordará. ese problema se genera pocas páginas.

MI CÓDIGO PHP

public function getPdfToAllEmpReport(){ //header("Content-type:application/pdf"); $user_id = Auth::user()->get()->id; $company_id = Auth::user()->get()->company_id; $input = Input::all(); if(!isset($input) && empty($input)){ $input = array(); } // Company based Userlist $userData = CompanyUser::getCompanyUserList()->toArray(); $userRewardsData = $this->getUsersRewards($userData,$input); $company = CompanyMaster::getCompanyDetails()->toArray(); $search_string = ""; if(!empty($company) && !empty($userRewardsData)){ PDF::SetTitle($company['company_name']." - All Employee Report"); PDF::SetHeaderMargin(5); PDF::SetFooterMargin(10); PDF::SetFont('','',10); PDF::SetHeaderData('', '', $company['company_name']." - All Employee Report", $search_string); PDF::SetMargins(10, 20, 10); PDF::AddPage(); $w = array(50,20,20,20,19,19,19,23); $sw = array(60,56,27,27,20); $h = 5; $total_height = 0; PDF::Ln(); PDF::SetFillColor(128, 0, 96); PDF::SetTextColor(255, 255, 255); PDF::SetFont('','B',9); // Data PDF::MultiCell($w[0], 10, "Worker Name", 'LRB', 'L' , 1, 0); PDF::MultiCell($w[1], 10, "Applause Received", 'RB', 'L', 1, 0); PDF::MultiCell($w[2], 10, "Drumbeat Received", 'RB', 'L' , 1, 0); PDF::MultiCell($w[3], 10, "Ding Received", 'RB', 'L' , 1, 0); PDF::MultiCell($w[4], 10, "Shoutout Sent", 'RB', 'L' , 1, 0); PDF::MultiCell($w[5], 10, "Rally Response", 'RB', 'L' , 1, 0); PDF::MultiCell($w[6], 10, "Project Reward", 'RB', 'L' , 1, 0); PDF::MultiCell($w[7], 10, "Engagement Donation", 'RB', 'L' , 1, 0); PDF::Ln(); $i=1; $total_height = 10; foreach ($userRewardsData['finalData'] as $user) { PDF::SetFillColor(38, 115, 38); PDF::SetTextColor(255,255,255); PDF::SetFont('','B',9); PDF::MultiCell($w[0], $h, $user['user_info']['full_name'], 'LRB', 'L', 1, 0); PDF::MultiCell($w[1], $h, number_format($user['applauseData']['count']), 'RB', 'L', 1, 0); PDF::MultiCell($w[2], $h, number_format($user['dingData']['count']), 'RB', 'L', 1, 0); PDF::MultiCell($w[3], $h, number_format($user['drumbeatData']['count']), 'RB', 'L', 1, 0); PDF::MultiCell($w[4], $h, number_format($user['shoutoutData']['count']), 'RB', 'L', 1, 0); PDF::MultiCell($w[5], $h, number_format($user['rallyResponceData']['count']), 'RB', 'L', 1, 0); PDF::MultiCell($w[6], $h, number_format($user['projectData']['count']), 'RB', 'L', 1, 0); PDF::MultiCell($w[7], $h, number_format($user['engagementData']['count']), 'RB', 'L', 1, 0); PDF::Ln(); PDF::SetFont('','',9); PDF::SetTextColor(0,0,0); $total_height = $this->setNewPage($total_height,$h,$search_string); if(!empty($user['applauseData']['data'])){ PDF::SetFillColor(180, 180, 180); PDF::MultiCell($sw[0], $h, "Applause - Reward Name", 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, "Issued by", 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "Active / Inactive", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, "Issue date", 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, "Points", 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); foreach ($user['applauseData']['data'] as $data) { PDF::SetFillColor(255, 255, 255); PDF::MultiCell($sw[0], $h, $data['reward_name'], 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, $data['from_user'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "YES", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, $data['attaboy_date'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, number_format($data['points']), 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); } } if(!empty($user['dingData']['data'])){ PDF::SetFillColor(180, 180, 180); PDF::MultiCell($sw[0], $h, "Ding - Reward Name", 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, "Issued by", 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "Active / Inactive", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, "Issue date", 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, "Points", 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); foreach ($user['dingData']['data'] as $data) { PDF::SetFillColor(255, 255, 255); PDF::MultiCell($sw[0], $h, $data['reward_name'], 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, $data['from_user'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "YES", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, $data['attaboy_date'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, number_format($data['points']), 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); } } if(!empty($user['drumbeatData']['data'])){ PDF::SetFillColor(180, 180, 180); PDF::MultiCell($sw[0], $h, "Drumbeat - Reward Name", 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, "Issued by", 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "Active / Inactive", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, "Issue date", 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, "Points", 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); foreach ($user['drumbeatData']['data'] as $data) { PDF::SetFillColor(255, 255, 255); PDF::MultiCell($sw[0], $h, $data['reward_name'], 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, $data['from_user'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "YES", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, $data['attaboy_date'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, number_format($data['points']), 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); } } if(!empty($user['shoutoutData']['data'])){ PDF::SetFillColor(180, 180, 180); PDF::MultiCell($sw[0], $h, "Shoutout - Reward Name", 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, "Issued by", 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "Active / Inactive", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, "Issue date", 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, "Points", 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $total_height+$h; if($total_height%260==0){ PDF::AddPage(); $total_height =0; } foreach ($user['shoutoutData']['data'] as $data) { PDF::SetFillColor(255, 255, 255); PDF::MultiCell($sw[0], $h, $data['reward_name'], 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, $data['from_user'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "YES", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, $data['attaboy_date'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, number_format($data['points']), 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); } } if(!empty($user['rallyResponceData']['data'])){ PDF::SetFillColor(180, 180, 180); PDF::MultiCell($sw[0], $h, "Rally Responce - Reward Name", 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, "Issued by", 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "Active / Inactive", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, "Issue date", 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, "Points", 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); foreach ($user['rallyResponceData']['data'] as $data) { PDF::SetFillColor(255, 255, 255); PDF::MultiCell($sw[0], $h, $data['reward_name'], 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, $data['from_user'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "YES", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, $data['attaboy_date'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, number_format($data['points']), 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); } } if(!empty($user['projectData']['data'])){ PDF::SetFillColor(180, 180, 180); PDF::MultiCell($sw[0], $h, "Project - Reward Name", 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, "Issued by", 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "Active / Inactive", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, "Issue date", 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, "Points", 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); foreach ($user['projectData']['data'] as $data) { PDF::SetFillColor(255, 255, 255); PDF::MultiCell($sw[0], $h, $data['reward_name'], 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, $data['from_user'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "YES", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, $data['display_issued_date'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, number_format($data['points']), 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); } } if(!empty($user['engagementData']['data'])){ PDF::SetFillColor(180, 180, 180); PDF::MultiCell($sw[0], $h, "Engagement - Reward Name", 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, "Issued by", 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "Active / Inactive", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, "Issue date", 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, "Points", 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); foreach ($user['engagementData']['data'] as $data) { PDF::SetFillColor(255, 255, 255); PDF::MultiCell($sw[0], $h, $data['reward_name'], 'LRB', 'L', 1, 0); PDF::MultiCell($sw[1], $h, $data['from_user'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[2], $h, "YES", 'RB', 'L', 1, 0); PDF::MultiCell($sw[3], $h, $data['display_issued_date'], 'RB', 'L', 1, 0); PDF::MultiCell($sw[4], $h, number_format($data['points']), 'RB', 'L', 1, 0); PDF::Ln(); $total_height = $this->setNewPage($total_height,$h,$search_string); } } $i++; $total_height = $this->setNewPage($total_height,$h,$search_string); } PDF::Output('hello_world.pdf','I'); } } private function setNewPage($total_height,$height,$search_string){ $total_height = $total_height+$height; if($total_height%275==0){ PDF::AddPage(); $total_height =10; } return $total_height; } 

MI SALIDA enter image description here

Estaba enfrentando el mismo problema y la solución de ingeniería para este problema terminó como una combinación de constantes mágicas y el uso de addPage si mi cálculo mostraba que deberíamos hacer un salto de página manual:

 $top_margin = 82; [...] if ($pdf->getY() > (300 /* A4 height */ - $top_margin + 40 /* another magic constant */)) { $pdf->addPage(); } 

Después de escribir cada fila. En su caso, probablemente necesite ajustar las constantes, pero esto solucionó mis problemas.

Parece un error, que la biblioteca está dispuesta a escribir detrás del final de la región de la página. No creo que podamos arreglar esto, porque el autor ya se movió al desarrollo de una nueva biblioteca en PDF tc-lib-pdf .