TCPDF is twice as slow as FPDF with the same code

I am currently using FPDF to create fairly complex reports and am trying to switch to TCPDF, but I found that my code working through TCPDF is about half as slow. Since my PDF files already take up to a minute to generate, I cannot afford this slowdown, but I would really like to use some TCPDF features (for example, bookmarking).

If anyone has any information on this issue, I would really appreciate you to have TCPDF speed up or just confirm that it is slower than FPDF, so I can forget about it and just stick with FPDF.

+6
php pdf fpdf tcpdf
source share
4 answers

Here is a sweet solution, beats 2 minutes for me. PDF files 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); } 
+4
source share

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

By default, TCPDF allows a subset of fonts to reduce the size of Unicode TTF embedded fonts; this process, which is very slow and requires a lot of memory, can be disabled using the setFontSubsetting (false) method;

It was a real solution for me.

+2
source share

Starting with version 5.9.067, TCPDF performance has been significantly improved. Each new release seems to work better. In addition, you can tune it to improve performance, as described at http://www.tcpdf.org/performances.php

+1
source share

TCPDF performance can be tuned by disabling unused functions in the configuration file and disabling slow functions, such as a subset of fonts. Using only the main fonts (e.g. Helvetica, Times, ...) in a mode other than UTF8, you can get good results. Alternatively, you can install XCache on your server to improve PHP performance. For more information, see the official http://www.tcpdf.org website and forums.

0
source share

All Articles