If you ever need to create PDFs on the fly with PHP, I highly recommend you use FPDF.

It can take a little tweaking, but basically you can do whatever you need to do to create any kind of PDF. If long as you know how to work with classes, you can make an incredibly powerful and versatile PDF generator, with what is a really lightweight library.

I work with Japanese a lot, which often causes encoding issues. Japan is bizarrely backwards in many aspects of computing, one of which is an insane reluctance to embrace UTF-8 for web development. Of course, PHP is not exactly known for its awesome UTF-8 support either, so you'd think it'd be hell to use FPDF for Japanese, but it isn't.

I saved the Japanese I needed in a mySQL database, as Unicode. However when I tried to extract it, all I could see was gibberish in the PDF. The same extracted data displayed as correct Japanese on a regular web page. This confused me. Turned out all I needed to do was this:

$legibleJapanese = iconv("UTF-8", "SJIS", $japaneseString);

in order to get it to work with FPDF.

I'll get more into the awesomeness of FPDF in a later post if I have time.

No comments:

Post a Comment