tags:

views:

619

answers:

3

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.

+1  A: 

I don't have an answer, but I've been recently working on implementing TCPDF and have been disappointed with the performance out-of-the-box. Did you ever find any information on the issue?

David Alan Hjelle
Unfortunately, no I did not. For now I'm continuing to use FPDF because I don't have a pressing need (yet) for TCPDF's features.
Jacob
A: 

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.

A: 

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