具有相同代码的TCPDF的速度是FPDF的两倍 [英] TCPDF twice as slow as FPDF with same code

查看:85
本文介绍了具有相同代码的TCPDF的速度是FPDF的两倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用FPDF创建一些相当复杂的报告,并试图升级到TCPDF,但是我发现通过TCPDF运行的相同代码的速度大约是原来的两倍.因为我的PDF已经花了多达一分钟的时间来生成,所以我真的负担不起这种速度,但是我真的很想利用TCPDF的某些功能(例如创建书签).

I currently use FPDF to create some fairly complicated reports and am trying to upgrade to TCPDF, but I've found that my same code running through TCPDF is about twice as slow. Because my PDFs already take up to a minute to generate I can't really afford to have this slowdown, but I'd really like to take advantage of some TCPDF features (like creating bookmarks).

如果有人对这个问题有一些了解,我会非常感激-您做过一些使TCPDF速度更快的事情,或者只是确认它比FPDF的运行速度慢,所以我可以忘记它,而坚持使用FPDF. /p>

If anyone has some information on this problem I'd really appreciate it - either things you did to make TCPDF faster, or just confirmation that it runs slower than FPDF, so I can forget about it and just stick with FPDF.

推荐答案

这是一个很好的解决方案,为我节省了2分钟. PDF将在3秒钟内创建!

Here is a sweet solution, shaves 2 minutes for me. PDFs are created in 3 seconds!

http://www. bitrealm.net/2010/08/tcpdf-is-slow-here-is-the-solution/

替换

$font = $this->_getTrueTypeFontSubset($font, $subsetchars);

与此:

/ Alcal: $font2cache modification
// This modification creates utf-8 fonts only the first time,
// after that it uses cache file which dramatically reduces execution time
if (!file_exists($fontfile.'.cached')){
// calculate $font first time
$subsetchars = array_fill(0, 512, true); // fill subset for all chars 0-512
$font = $this->_getTrueTypeFontSubset($font, $subsetchars); // this part is actually slow!
// and then save $font to file for further use
$fp=fopen($fontfile.'.cached','w');
$flat_array = serialize($font); //
fwrite($fp,$flat_array);
fclose($fp);
}
else {
// cache file exist, load file
$fp=fopen($fontfile.'.cached','r');
$flat_array = fread($fp,filesize($fontfile.'.cached'));
fclose($fp);
$font = unserialize($flat_array);
}

这篇关于具有相同代码的TCPDF的速度是FPDF的两倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆