Copy Files into Joomla! Installation

With all the files ready, we can now copy them into proper locations on your server. Use FTP or SFTP to copy all the files and three directories cache, config and images inside your tcpdf folder to the directory libraries/tcpdf at your Joomla! installation. (You may want to rename the original libraries/tcpdf directory to another name, and then create a new libraries/tcpdf directory just to be safe.)

Next, copy the file adobemingstd-light.php you created into language/pdf_fonts at your Joomla! installation. Do the same for helvetica.php and uni2cid_ac15.php in your local tcpdf/fonts.

Edit Language Description XML File

The font used for PDF generation is specified in the language description XML file inside respective language folder. For Traditional Chinese, it's the language/zh-TW/zh-TW.xml. We need to add the following line between and tags:


Modify Joomla! PDF Script

There seems to be a bug in Joomla! PDF script. It fails to correctly set the font for the article content. Please open the file libraries/joomla/document/pdf/pdf.php with your favorite editor on your server. Find the function render( $cache = false, $params = array()). Insert the following line right before the line $pdf->WriteHTML($this->getBuffer(), true);

$pdf->setFont($font, '', 10);

Optional Step

This step is optional if you can tolerate the ugly layout of article content in the resulting PDF file. The problem is that TCPDF uses white spaces to format the layout while Chinese characters are packed next to each other without spaces in between.

To fix this problem, you will have to modify the TCPDF core program. Use an editor to open the file libraries/tcpdf/tcpdf.php on your server. Find the public function Write($h, $txt, $link='', $fill=0, $align='', $ln=false, $stretch=0, $firstline=false) definition. Inside that function, look for the following line:

if (preg_match("/[\s]/u", $this->unichr($c))) {

and replace it with this line

if (preg_match("/[\s\p{Lo}]/u", $this->unichr($c))) {

Now try generating a Chinese PDF file from your Joomla! site's frontend, and see whether the layout has been improved. If not, your server doesn't have a PCRE library with the Unicode properties support compiled in. You can check it on the server using this command:

$ pcretest -C

You should see an output similar to the following

PCRE version 6.6 06-Feb-2006
Compiled with
  UTF-8 support
  Unicode properties support
  Newline character is LF
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack

If it shows that Unicode properties support is not enabled, then the modification won't work. In that case you can download PCRE library source code and compile it with Unicode properties support enabled. Once the newly compiled PCRE library is installed, the layout in generated Chinese PDF should become more acceptable.

If You're Lazy.....

Well, if all these seems daunting, there is a short cut. I post an archive file including all the files, except the file mentioned at the optional step (because of the special PCRE library requirement), at Joomla! Taiwan. You can simply download it and put it on your server.

FaLang translation system by Faboba