Custom font and special characters in TCPDF

Summary: When using TCPDF (or any other PHP PDF library) use this website to convert your fonts when you have troubles with special characters.

For a client project we have to generate a lot of PDF files. At first we used DOMPDF, but it was painfully slow (taking up to 10 minutes for a ~30 page document) and driving us crazy with the incorrect rendering of special characters like ß, € (euro sign) and £ (pound sign).

So we decided to rewrite the whole PDF part of our webapp with the TCPDF library. This made the generation a lot faster! (12.5 seconds now vs. 10 minutes with DOMPDF) On MacOS X with preview the special characters where also looking good, even with a custom font like MyriadPro. Great!

But when we tested the PDFs in Windows with Acrobat Reader all the special where going crazy once again. The width of the characters seemed to be interpreted as 0, so everything around this characters was printed right on top of the special character.

After searching for a while I found a Stack Overflow question asking why the pound sign wouldn’t show up when using a custom font with TCPDF. It seemed a lot like my problem and the first answer was spot on.

When converting your font with the TCPDF addFont-methods it is possible that there is going something wrong and the special characters won’t work correctly. For me using this free and easy font-convert website did the trick. I threw my fonts at it and it converted them perfectly. All the problems disappeared at once.

Note that you must fill in the “final name wanted” with care! For “Myriad Pro bold” I had to use the fontname “myriadprob” for regular it is just “myriadpro”, italic is “myriadproi” etc. Without the proper names TCPDF will not recognize your fontfiles!

Hope this will save you some time and a lot of frustration. :)