title: TCPDF optimize performance
body: <p>I've done a lot of searching and testing. My task is to optimize PDF generation form HTML. </p>
  
  <p>My code is:</p>
  
  <pre><code>&lt;?php
  define('K_TCPDF_EXTERNAL_CONFIG', true); 
  
  require('static_config.php');
  require("hipero_pdf.class.php");
  
  $pdf = new hipero_TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
  
  $pdf-&gt;SetHeaderData(PDF_HEADER_IMAGE, PDF_HEADER_IMAGE_WIDTH);
  $pdf-&gt;SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  $pdf-&gt;SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  $pdf-&gt;SetHeaderMargin(PDF_MARGIN_HEADER);
  $pdf-&gt;SetFooterMargin(PDF_MARGIN_FOOTER);
  $pdf-&gt;SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  $pdf-&gt;setImageScale(PDF_IMAGE_SCALE_RATIO);
  $pdf-&gt;setLanguageArray($l);
  $pdf-&gt;SetFont('dejavusans', '', 10);
  
  $pdf-&gt;AddPage();
  
  $pdf-&gt;SetTextColor(0, 0, 0);
  
  $pdf-&gt;writeHTML(PDF_SYNEO_HTML, true, false, true, false, '');
  $pdf-&gt;Output('../../Content/Offers/Generated/'.PDF_SYNEO_FILENAME.'.pdf');
  ?&gt;
  </code></pre>
  
  <p>My HTML is a bit messy, but test shows this is have almost no impact on performance.</p>
  
  <p>Every peace of code take less than 1 sek. to be parsed. Only this take longer:</p>
  
  <p>$pdf->AddPage - 3 sek.</p>
  
  <p>$pdf->writeHTML - 9 sek.</p>
  
  <p>$pdf->Output - 5 sek.</p>
  
  <p>This is on IIS server (shared hosting). </p>
  
  <p>Please tell me how to optimize this methods. I have no more ideas :/.</p>