title: Speed Up TCPDF File Generation
body: <p>I've been using TCPDF in order to convert HTML to pdf.</p>
  
  <p>I noticed that single page invoice is generated in 5 seconds while a 7 page invoice is generated in 55 seconds, for a reason I can't tell.</p>
  
  <p>I'm using the latest TCPDF version, and I've also tried using this solution and also set setFontSubsetting(false) , but none of those solutions have improved TCPDF slow files generation.</p>
  
  <p>This is the program's full code :</p>
  
  <pre><code>    &lt;?php
  set_time_limit(0);
  require('modifyDate.php');
  require('createQuery.php');
  
  //GET FORM DATA
  if(isset($_POST['submitMeshavek']))
  {
  $saleStart=$_POST['saleStart'];
  $saleEnd=$_POST['saleEnd'];
  $saleWeek=$_POST['weekId'];
  $growerId=$_POST['growerId'];
  $reportType=$_POST['reportType'];
  }
  
  //REQUIRE TCPDF
  require_once('tcpdf/config/lang/eng.php');
  require_once('tcpdf/config/lang/heb.php');
  require_once('tcpdf/tcpdf.php');
  
  class MYPDF extends TCPDF {
  
      //Page header
      public function Header() {
          // Set font
          $this-&gt;SetFont('helvetica', 'B', 20);
          // Title
          $this-&gt;Cell(0, 15, '&lt;&lt; TCPDF Example 003 &gt;&gt;', 0, false, 'C', 0, '', 0, false, 'M', 'M');
      }
  
      // Page footer
      public function Footer() {
          // Position at 15 mm from bottom
          $this-&gt;SetY(-15);
          // Set font
          $this-&gt;SetFont('helvetica', 'I', 8);
          // Page number
          $this-&gt;Cell(0, 10, 'Page '.$this-&gt;getAliasNumPage().'/'.$this-&gt;getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
      }
  }
  
  
  
  // create new PDF document
  $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  
  // set document information
  /*
  $pdf-&gt;SetCreator(PDF_CREATOR);
  $pdf-&gt;SetAuthor('Nicola Asuni');
  $pdf-&gt;SetTitle('TCPDF Example 018');
  $pdf-&gt;SetSubject('TCPDF Tutorial');
  $pdf-&gt;SetKeywords('TCPDF, PDF, example, test, guide');
  */
  // SET CUSTOMIZED DATE INCLUDED HEADER
  $headerSDate=reverseLongDate($saleStart);
  $headerEDate=reverseLongDate($saleEnd);
  $header="";
  $header.="\t";
  $header.=Date("d-m-Y h:m:s");
  $header.="\n";
  $header.='מועדון המגדלים יוסי חותה פירות וירקות';
  $header.="\n";
  $header.='דו"ח שיווק ללקוח לתאריכים '.$headerSDate." עד ".$headerEDate;
  
  $pdf-&gt;SetHeaderData("","" ,"",$header); 
  //$pdf-&gt;SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
  
  
  
  // set header and footer fonts
  $pdf-&gt;setHeaderFont(Array("dejavusans", '', "15"));
  $pdf-&gt;setFooterFont(Array("dejavusans", '', "12"));
  
  // set default monospaced font
  $pdf-&gt;SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  
  //set margins
  $pdf-&gt;SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  $pdf-&gt;SetHeaderMargin(0);
  $pdf-&gt;SetFooterMargin(PDF_MARGIN_FOOTER);
  
  //set auto page breaks
  $pdf-&gt;SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  
  //set image scale factor
  $pdf-&gt;setImageScale(PDF_IMAGE_SCALE_RATIO);
  
  // set some language dependent data:
  $lg = Array();
  $lg['a_meta_charset'] = 'UTF-8';
  $lg['a_meta_dir'] = 'rtl';
  $lg['a_meta_language'] = 'fa';
  $lg['w_page'] = 'page';
  
  //set some language-dependent strings
  $pdf-&gt;setLanguageArray($lg);
  
  // ---------------------------------------------------------
  
  // set font
  $pdf-&gt;SetFont('dejavusans', '', 12);
  
  // add a page
  $pdf-&gt;AddPage();
  // -----------------------------------------------------------------------------
  
  
  
  
  /*
  $regularSaleStart=reverseDate($saleStart);
  $regularSaleEnd=reverseDate($saleEnd);
  $header='&lt;h2&gt;מועדון מגדלים יוסי חותה פירות וירקות&lt;/h2&gt;';
  $header.="דוח שיווק ללקוח לתאריכים                 ".$regularSaleEnd." ".$regularSaleStart;
  
   public function Header() {
          // Set font
          $this-&gt;SetFont('dejavusans', '', 10);
          // Title
          $this-&gt;Cell(0, 15, '&lt;&lt; TCPDF Example 003 &gt;&gt;', 0, false, 'C', 0, '', 0, false, 'M', 'M');
      }
  */
  
  if($reportType=='customer')
  {
      include('reportType/customer.php');
  }
  else
      if($reportType=='newCustomer')
      {
          include('reportType/customerNew.php');
      }
      else 
          if($reportType=='collection')
              {
              include('reportType/collect.php');
              }
                  else 
                      if($reportType=='grower')
                      {
                          include('reportType/grower.php');
                      }
  
  ob_clean();
  //$pdf-&gt;writeHTML($html, true, false, false, false, '');
  $pdf-&gt;writeHTML($html, true, 0, true, 0);
  //Close and output PDF document
  $pdf-&gt;Output('example_048.pdf', 'I');
  
  $pdf-&gt;writeHTML($html, true, 0, true, 0);
  //Close and output PDF document
  $pdf-&gt;Output('examp.pdf', 'I');
  
  
  ?&gt;
  </code></pre>
  
  <p>It seems like I've been trying to do anything possible in order to make TCPDF run faster, Any suggestion will be appreciated, Thanks in advance !</p>