TCPDF very slow generation of dynamic arabic PDF

别说谁变了你拦得住时间么 提交于 2019-12-11 06:42:35

问题


I've been using a combination of nusoap & TCPDF to ping a web service and dynamically fill out a PDF with content.

The PDF itself (in english) takes around 8-9 seconds to complete for about 36 pages, some of which include bar charts. I'd also like to note that due to the format that the data is received in, I am using "writeHTML" to present it on the PDF.

My major issue came around when I started trying to generate the same PDFs with arabic translations. I'm using the "Almohanad" font as described in the TCPDF examples, and the processing time jumped up to 2 minutes.

I've tried using the following fix (which caches font files) : http://www.bitrealm.net/2010/08/tcpdf-is-slow-here-is-the-solution/

Alas it did not seem to work (the ".CACHED" file didn't appear even though I gave the tcpdf file full user permissions)! I do have to mention that i needed to insert ob_clean() after the "require_once" section of my php file to avoid the following error:

"TCPDF error: Some data has already been output, can't send PDF"

I checked my php files for white space and found nothing out of place.

In conclusion, could anyone help me speed up the generation of the arabic PDF using TCPDF, or else recommend a quicker alternative?

Thanks for your time.


回答1:


On the latest TCPDF version, the almohanad was replaced by aefurat and aealarabiya fonts.

The latest TCPDF version automatically convert fonts into TCPDF format using the addTTFfont() method, so you can easily add new arabic fonts as on the example below:

// convert TTF font to TCPDF format and store it on the fonts folder
$fontname = $pdf->addTTFfont('/path-to-font/FontName.ttf', 'TrueTypeUnicode', '', 96);
// use the font
$pdf->SetFont($fontname, '', 14, '', false);

Check also the http://projects.arabeyes.org website for alternative Arabic fonts and the http://www.tcpdf.org website for the new fonts guide.




回答2:


Try mPDF as an alternative it is very easy to use and it amazingly supports RTL languages like Arabic, Hebrew, Farsi/Persian, Urdu and Pashto. And this is an example demonstrates that.



来源:https://stackoverflow.com/questions/5080669/tcpdf-very-slow-generation-of-dynamic-arabic-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!