windows TCPDF - 如何使打印速度更快?非常非常慢,1320条记录用了40分钟
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8186673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TCPDF - How to make the printing faster? It is very very slow, 1320 records took 40 minutes
提问by Peter Brooks
Using Zend framework and TCPDF this is taking 40 minutes to print the Test.pdf. I having now no idea how to reduce this abnormal time to something normal?
使用 Zend 框架和 TCPDF 打印 Test.pdf 需要 40 分钟。我现在不知道如何将这个不正常的时间减少到正常的时间?
set_time_limit(0);
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$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->setFontSubsetting(true);
$pdf->SetFont('dejavusans', '', 8, '', true);
$pdf->AddPage();
/* Database mysql gives the records and it is wrapped with <table> */
$html = "<table>1310 records.... with some simple <tr><td></td></tr></table>";
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$pdf->Output('Test.pdf', 'I');
exit;
Follow up:(tune the performance)
跟进:(调整性能)
1) php.ini: memory_limit = 512M max_execution_time = 0
1) php.ini: memory_limit = 512M max_execution_time = 0
2) Codeing $pdf->setFontSubsetting(false); // true to false
2) 编码 $pdf->setFontSubsetting(false); // 真到假
3) Debug shows, following taking the whole time
3)调试显示,下面花时间
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true , $align='', $autopadding=true);
回答by Peter Brooks
Since no other answers have been forthcoming, I would highly recommend a good look at MPDF(GPL) as it's much faster than TCPDF. I've had operations on one server that took approx three minutes using TCPDF being reduced to seconds with MPDF. I would only assume that some format of my HTML -> PDF was hitting some inefficient function in TCPDF.
由于没有其他答案,我强烈建议好好看看MPDF(GPL),因为它比 TCPDF 快得多。我在一台服务器上进行了大约三分钟的操作,使用 TCPDF 使用 MPDF 将其减少到几秒钟。我只会假设我的 HTML -> PDF 的某种格式在 TCPDF 中遇到了一些低效的功能。
Anyway I present the following code which helped me convert HTML -> PDF.
无论如何,我提供以下代码帮助我转换 HTML -> PDF。
$mpdf = new mPDF('c');
$mpdf->setDisplayMode('fullpage');
$stylesheet = file_get_contents('css/core.css');
$mpdf->WriteHTML($stylesheet,1);
$html = "<table>1310 records.... with some simple <tr><td></td></tr></table>";
$mpdf->WriteHTML($html);
$mpdf->Output(standardize(ampersand('filename', false)) . '.pdf', 'D');
This code provides a PDF outputted as a downloadable file, the MPDF documentation gives lots of other examples to suit your needs.
此代码提供作为可下载文件输出的 PDF,MPDF 文档提供了许多其他示例以满足您的需求。
回答by Jim H
We use mpdf
mainly because I can just "include" it with no installation.
There was some minor tweak that needed to be added to php.ini, mbstring I think.
我们使用mpdf
主要是因为我可以直接“包含”它而无需安装。有一些小的调整需要添加到 php.ini,我认为是 mbstring。
I was able to get 75 pages a minute up to 100 pages per minute by shrinking the HTML I was feeding the WriteHTML
verb. We do not have any graphics.
通过缩小我提供给WriteHTML
动词的 HTML,我能够每分钟获得 75 页到每分钟 100 页。我们没有任何图形。
Then I use ghostscript
to sort and cat pdfs (15 or so pages) per person receiving them. That cat process takes about 3 minutes per 800-1000-pages for the 50 or 60 people receiving a report at one destination.
然后我ghostscript
习惯于对每个接收它们的人进行排序和分类 pdf(15 页左右)。对于在一个目的地接收报告的 50 或 60 人来说,每 800-1000 页的处理过程大约需要 3 分钟。
All this on a box mostly sitting there for nothing else.
所有这些都放在一个盒子里,大部分时间都坐在那里,别无他物。
回答by Jefferson Pugliese
One of the causes of the TCPDF slow performance could be images inserted from external URLs. DNS resolution and file downloading take time and slow down the PDF generation process.
TCPDF 性能缓慢的原因之一可能是从外部 URL 插入的图像。DNS 解析和文件下载需要时间并减慢 PDF 生成过程。