使用相同的代码,TCPDF 比 FPDF 慢两倍

发布于 2024-08-21 13:10:32 字数 234 浏览 5 评论 0原文

我目前使用 FPDF 创建一些相当复杂的报告,并尝试升级到 TCPDF,但我发现通过 TCPDF 运行的相同代码大约慢两倍。因为我的 PDF 生成时间已经长达一分钟,所以我实在无法忍受这种速度变慢的情况,但我真的很想利用一些 TCPDF 功能(例如创建书签)。

如果有人有关于这个问题的一些信息,我真的很感激 - 无论是你为使 TCPDF 更快而做的事情,还是只是确认它的运行速度比 FPDF 慢,这样我就可以忘记它并坚持使用 FPDF。

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).

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

水溶 2024-08-28 13:10:32

这是一个甜蜜的解决方案,为我节省了 2 分钟。 3 秒内即可创建 PDF!

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);
}

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/

Replace

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

with this:

/ 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);
}
冷情妓 2024-08-28 13:10:32

http://www.tcpdf.org/performances.php

默认情况下 TCPDF 启用字体子集化以减少嵌入 Unicode TTF 字体的大小,这个过程非常慢并且需要大量内存,可以使用 setFontSubsetting(false) 方法关闭;

这对我来说是真正的解决方案。

http://www.tcpdf.org/performances.php

By default TCPDF enables font subsetting to reduce the size of embedded Unicode TTF fonts, this process, that is very slow and requires a lot of memory, can be turned off using setFontSubsetting(false) method;

This was the real solution for me.

樱花细雨 2024-08-28 13:10:32

自版本 5.9.067 以来,TCPDF 性能得到了显着提高。
每个新版本似乎都表现更好。
此外,您可以将其设置为提高性能,如 http://www.tcpdf.org/performances.php< 中所述/a>

Since version 5.9.067 TCPDF performances were drastically improved.
Each new release seems performing better.
Additionally you can set it to boost performances as explained at http://www.tcpdf.org/performances.php

小女人ら 2024-08-28 13:10:32

可以通过禁用配置文件上未使用的功能并关闭字体子集等慢速功能来调整 TCPDF 性能。
在非 UTF8 模式下仅使用核心字体(如 Helvetica、Times 等)可以获得良好的性能。
此外,您可以在服务器上安装 XCache 以提高 PHP 性能。
请查看官方 http://www.tcpdf.org 网站和论坛以获取更多信息。

TCPDF performances can be tuned by disabling unused features on the configuration file and turn off slow features like font subsetting.
Using only core fonts (like Helvetica, Times, ...) in non-UTF8 mode you can get good performances.
Additionally you can install XCache on you server to boost PHP performances.
Check the official http://www.tcpdf.org website and forums for further information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文