I have large amount of data that needs to be process and add as tables in PDF using Codeigniter. PDF contain some HTML elements, images, icons, and need lots of alignment using CSS.
So, to achieve this goal I did some search and checked which PDF generation plugin will be suitable for me. So, rather than selecting FPDF, TCPDF or HTMLTOPDF, mPDF etc. I chosen DOMPDF as it is supporting most of the css styles and it serves my purpose as well.
Initially, it was working fine as data was not much heavy and PDF with 10-20 pages was generating fine. But, as data gets increased and need to put about 35-45 pages in my PDF, system gets time out.
So, I changed server settings and made "4GB of RAM with 1 CPU to 8GB of RAM with 4 CPUs". And, increased max_execution_time to 90, memory_limit to 384M but still DOMPDF not rendering large PDFs having pages more than about 35.
I have set landscape mode to download PDF instead save it.
Below is the PHP code in my controller of Codeigniter.
$this->load->library('pdf');
$teaminfo=$this->pdf_model->getTeamName($teamid);
$data=array();
if($teaminfo != false)
{
$teamname=$teaminfo->team_name;
$data['teamname']=$teamname;
$formateddate=date('F j, Y');
$data['teammeetingdate']=$formateddate;
//add code to get and pass the terms and replacement array
$termsList=$this->getTermsArray($teamid);
$data['searchterms']=$termsList['searchterms'];
$data['replacement']=$termsList['replacement'];
//get teammeeting roster
$data['rosterlist']=$this->getRostertable($teamid);
$personwisedata=$this->getteammemberData($teamid);
$data['personwiseData']=$personwisedata;
$kmresponse=$this->get_last_six_month_keymetrics_details_by_userid_without_owner($teamid);
$data['noownerkmdata']=$kmresponse;
//set pdf title
$teamnametitle='My PDF Notes - '.$teamname.' '.date("m.d.Y");
$pdftitle=$teamnametitle.'.pdf';
$this->pdf->set_paper('a4', 'landscape');
$this->pdf->set_option( 'enable_font_subsetting' , true );
$this->pdf->load_view('backend/Pdf/teammeeting_pdf', $data);
$this->pdf->render();
$this->pdf->stream($pdftitle,array("Attachment" => 0));
}
For small size PDFs it is working fine. But, when long PDF need to generate execution stops and showing error "Internal Server Error" on page.
When I just print output on browser by putting exit, it works within a minute, but when I send that html to render on PDF and stream it, system stops execution.
I tried to set max_execution_time and memory_limit through htaccess and ini_set but it not helped me.
Hope so anyone will help me.