Using PDF::API2 I wrote a perl script to create an invoice PDF file with Japanese text. The file encoding is utf8 and I have "use utf8" in the header. If I declare the variables inside the script, everything is perfect. However, if I get the variables data from my mysql database (also utf8), the PDF file shows garbled characters instead of Japanese.
Next, instead of the database, I tried with requiring a data.lib file (also utf8) that listed the variables. Again, garbled characters. It seems that the only way it works is when the variables are listed in the script itself, which makes it impossible to use for e.g. PDF files for separate customers, short of making the whole script for every customer again and again... Is there a solution somewhere? Thanks!
I found the solution! Using Perl's Encode module, $last_name = decode("utf8", $$hashref{last_name}); (from mysql) or $last_name = decode("utf8", $last_name); (from .lib file) will do the trick. I still don't understand why a hardcoded variable is OK and an "imported" variable is not, but as long as it is fixed....