开发者

TCPDF Performances..Split large HTML blocks in smaller pieces?

I am using TCPDF to generate a PDF from HTML. I am having some slow loading t开发者_StackOverflow社区imes so was reading http://www.tcpdf.org/performances.php and it says to "Split large HTML blocks in smaller pieces", how would I do this and how big should I make these smaller pieces?

Thanks


This may be misunderstood, but here is my interpretation.

HTML has what is known as block elements, which are elements which have newlines both before and after -- in effect, a block element occurs on its own line, as in no other element may be left or right of it. An example of a block element would be <div>, <p>, or <h2>. This is in contrast to inline elements, such as <strong>, <span>, or <a>.

That said, it is possible that the algorithm TCPDF uses to transform HTML to PDFs is profoundly affected by the size of block elements -- that is, block elements which contain, in turn, lots of other elements and text. Think about it as building a bridge over a span of water; it is much easier to build hundreds of little bridges over a creek than it is to build one bridge over the English channel. For that same reason, transforming dozens of smaller blocks could be easier than transforming one large one.

As far as accomplishing this task, it may be difficult as it seems to require both restructuring of the HTML and restyling of the CSS. Also, some styling is only possible -- well, at least only practical -- by nesting block elements. For example, many page layouts make use of a wrapper block which is used for horizontal centring. What impact do nested block elements have on TCPDF? You may want to do research along this nature, either by searching for people who have already conducted such benchmarks or by benchmarking these things yourself. In any case, there isn't enough information on the page you linked to.

Other solutions may be to try FPDF, which may offer you better performance. Have you tried adjusting the fonts already?

These questions may provide more information.

  • Bloated PDF created by TCPDF
  • TCPDF twice as slow as FPDF with same code


In my experience, the thing that worked better to reduce loading time was to avoid font subsetting like this

$pdf->setFontSubsetting(false) ;

Usually rendering time is one tenth or less with that options set


The newer TCPDF version have deeply improved the performances of font subsetting method, so now it should be fine using it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜