Reputation: 93
I've done a lot of searching and testing. My task is to optimize PDF generation form HTML.
My code is:
<?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->SetHeaderData(PDF_HEADER_IMAGE, PDF_HEADER_IMAGE_WIDTH);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setLanguageArray($l);
$pdf->SetFont('dejavusans', '', 10);
$pdf->AddPage();
$pdf->SetTextColor(0, 0, 0);
$pdf->writeHTML(PDF_SYNEO_HTML, true, false, true, false, '');
$pdf->Output('../../Content/Offers/Generated/'.PDF_SYNEO_FILENAME.'.pdf');
?>
My HTML is a bit messy, but test shows this is have almost no impact on performance.
Every peace of code take less than 1 sek. to be parsed. Only this take longer:
$pdf->AddPage - 3 sek.
$pdf->writeHTML - 9 sek.
$pdf->Output - 5 sek.
This is on IIS server (shared hosting).
Please tell me how to optimize this methods. I have no more ideas :/.
Upvotes: 3
Views: 7911
Reputation: 10536
I also had an issue with TCPDF performance. I followed the guidelines cited at http://www.tcpdf.org/performances.php. What I could take from it :
Hope it helps !
Upvotes: 2
Reputation: 39
At TCPDF website, there's a page which advises avoiding the use of writeHTML if possible. Other than that, it also advises avoiding use big HTML blocks. There's more at http://www.tcpdf.org/performances.php where they explain you can turn off additional options to make rendering faster.
Upvotes: 3