Skip to content

Fixing problems with Magento creating empty invoice PDFs

I recently had a problem where Magento was producing the PDF invoice, but no text was visible. After some investigation it turned out it was an issue with the hosting configuration, rather than a problem with Magento at all. Fortunately my Magento hosts, nethosted, are switched on and got the configuration issue fixed in no time once it had been identified…

Initially I assumed this was a problem with the web server being unable to find the path to the default LinLibertine font used by Magento, and hence went about editing /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php so that it specified one of the default PDF fonts. There’s a decent tuitorial on editing the PDF invoice on Varien’s site. However, I still found the same thing. The invoice was created, but none of the text was visible.

Turning on logging and looking through var/logs/system.log files found this entry:

ERR (3):
Notice: iconv() [<a href='function.iconv'>function.iconv</a>]:
Wrong charset, conversion from `UTF-8' to `UTF-16BE' is not allowed  in /public_html/lib/Zend/Pdf/Resource/Font/Type0.php on line 241

This appeared to be a known issue, as detailed in this post on, so I went through and made the changes they suggested. But still it failed!

So what next? Magento uses the Zend_Framework Zend_Pdf class for all of it’s PDF generation functionality, so whilst looking through the source for this class it became clear that it relies heavily on the iconv() function to convert text into UTF-16BE (Big Endian) encoded text. If this function is not able to correctly convert the UTF-8/ISO/Windows encoded text you feed it, you’ll get a PDF with no text. So I decided to test this function was working correctly on my live host with a little test script.

$string = "Some text";
$newstr = iconv("UTF-8", "UTF-16BE", $string);
print "Converted: " .$newstr;

If this script throws any errors for you, you’ll never be able to use the Magento PDFing functionality until your web host fixes the problem with iconv. In some hosting environments, especially those where each user runs Apache “chrooted”, your host may need to add to the chroot path¬† the gconv or libiconv binaries, otherwise iconv cannot work. Essentially the iconv php function relies on external binaries to do it’s work, and if Apache/php can’t find those binaries then it will fail. Just hope your host is as accommodating as nethosted were for me.

Need help with Magento or creating a Magento ecommerce store? Please give us a call on +44(0)1225 309162 or email us…

This entry was posted in Magento and tagged , , , , . Bookmark the permalink.


Sorry, comments are closed on this page.