TCPDF 优化性能
我做了很多搜索和测试。我的任务是优化 HTML 的 PDF 生成。
我的代码是:
<?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');
?>
我的 HTML 有点乱,但测试表明这对性能几乎没有影响。
每和平代码花费不到 1 sek。待解析。只是这需要更长的时间:
$pdf->AddPage - 3 sek。
$pdf->writeHTML - 9 瑞典克朗。
$pdf->输出 - 5 秒。
这是在 IIS 服务器(共享主机)上。
请告诉我如何优化这个方法。我没有更多的想法:/。
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 :/.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 TCPDF 网站上,有一个页面建议尽可能避免使用 writeHTML。除此之外,它还建议避免使用大的 HTML 块。
http://www.tcpdf.org/performances.php 上有更多内容,他们解释了您可以关闭其他选项以使渲染速度更快。
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.
我还遇到了 TCPDF 性能问题。我遵循 http://www.tcpdf.org/performances.php 引用的指南。我可以从中得到什么:
希望有帮助!
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 !