Updating the TCPDF library in Joomla! 1.5
TCPDF is an excellent PHP class for creating PDFs from dynamic (or static, for that matter) web content. Unfortunately, the version of TCPDF bundled with Joomla! 1.5 (all 1.5 releases after at least 1.5.8 - someone please correct me if I am wrong - was version 2.6.000_PHP4, dated March 7, 2008. It's also not very PHP 5.3-friendly (there are other parts of Joomla! 1.5 which are not fully compatible with PHP 5.3, but this article will focus on TCPDF). Time to freshen up, methinks.
Okay, let's get one thing out of the way quickly: Joomla! 1.5, as stable as it is, has now gone well beyond EOL. Joomla! 1.6 was a bust, quickly followed by 1.7 (never tried it), then on to the 2.x branch, and suddenly, we find ourselves at 2.5 and 3.1. To make matters worse, the Joomla! folks don't have much regard for the cost of upgrading. It seems like every minor release is a migration and not an upgrade, and even applying a patch from, say, 1.5.22 to 1.5.26 (the last stable release of the 1.5 branch) requires careful testing for compatibility with plugins and even fonts and templates.
Indeed, it is this difficulty in maintaining Joomla! which makes me move more and more toward WordPress for more than just blog installations. However, I'm moving beyond the scope of this article.
One of the main annoyances with Joomla! 1.5 running under PHP 5.3 is the noise generated in the PHP error log concerning deprecated functions, namely:
PHP Deprecated: Function set_magic_quotes_runtime() is deprecated in blahblahblah on line nnnn
Yes, you could go through the steps outlined here to comment calls to set_magic_quotes_runtime() (though I can think of easier ways to recursively replace text strings using Perl 1 than the methods described in the reference). However, like fixing an old car, when you're done, you still have TCPDF version 2.6, albeit patched to be a little less noisy.
This article quashes the noise and gets you a better performing PHP class to boot, with less effort (I hope).
I have several remaining Joomla! 1.5 installations running on the server, with upgrades planned for later this year. Of course, that's what I said last year, so... The thing to do in the meantime is patch them as best I can until clients take the plunge and/or I get ambitious (with my own sites).
I'll go through what's necessary for upgrading TCPDF to version 6.0.018, released just days ago (May 19, 2013), under Joomla! 1.5.26 (if you have an earlier 1.5 Joomla! release, the steps should be similar, though you may want to consider an interim update to 1.5.26).
First, back up your existing libraries/tcpdf directory (I just renamed mine to tcpdf-old) and libraries/joomla/document/pdf/pdf.php (I copied this one to pdf.php.old).
Next, obtain the latest TCPDF from the project page, and either unpack it locally or move the zip/tarball/archive to your web server to extract it. Inside the archive, the directory tree will totally replace the tcpdf one you now have, which is why I recommend just renaming that (do not copy over the existing directory; you want a clean install of the new package).
Remove the examples directory from the tcpdf tree, as it is superfluous for this exercise.
Finally, open libraries/joomla/document/pdf/pdf.php and look for the following:
// Fonts path define("K_PATH_FONTS", JPATH_SITE.DS.'language'.DS."pdf_fonts".DS);
(in Joomla! 1.5.26, these are lines 81-82). Edit the font path to point to TCPDF's own fonts, and not the ones in Jooma's pdf_fonts directory, as in:
// Fonts path define("K_PATH_FONTS", K_PATH_MAIN.DS."fonts".DS);
Then, to avoid a call to an undefined function in TCPDF which has been deprecated 2, look for:
// Initialize PDF Document $pdf->AliasNbPages();
(in Joomla! 1.5.26, these are lines 179-180). Change them to read:
// Initialize PDF Document // remove this next line, as it is deprecated in TCPDF > 5.9 // $pdf->AliasNbPages();
and save the file.
That's it.
Why the font path edit?
TCPDF version 4.0.032 changed the default font to be Helvetica. Joomla!'s default PDF font seems to be FreeSans 3, and Helvetica is not usually present in language/pdf_fonts. Yes, you can make a mess by dumping all of the included fonts in the TCPDF 6 package into language/pdf_fonts, but why?
- Many examples abound. See Joseph Scott's blog for a quick refresher. ↩
- See this discussion in the Drupal forum, as this is not uncommon. ↩
- according to a reliable source in this discussion in the Joomla! forum ↩
Last Updated on by
Leave a comment
You must be logged in to post a comment.