Tag Archives: utf8

FPDF: How to use a Degree Symbol in a Generated PDF Tips, Tricks and Tutorials 29 SEP 2017

I’ve been using the FPDF PDF generator library for years now as the de facto method for my PHP projects to produce PDF reports. However, one minor annoyance is that the generated PDF files often falter when it comes to the inclusion of certain special characters – like the degree symbol (°) as an example.  (Basically, something like °C becomes °C in the final document)

The reason for this happening is that Arial, the default used/included font, is of type ISO-8859-1 while the degree symbol is UTF-8 encoded. So in order for us to include special symbols or characters from other languages, we need to either try and convert them into our font compatible ISO-8859-1 format, or perhaps switch to using a different TrueType or Type1 font (which then would contain the desired character set).

Now while UTF-8 support is available via a modified class, the easiest way to fix the degree symbol issue without having doing any real work is to simply make use of the PHP utf8_decode function, which convert UTF-8 encoded strings to their ISO-8859-1 equivalents.

In other words outputting utf8_decode(“°C”) to your PDF should result in the expected °C

Related Link: FPDF PDF Generator Library

A Test String for UTF-8 and Internationalization Work Tips, Tricks and Tutorials 02 NOV 2010

As an English-speaking, South African developer, I craft all my work for an English-speaking audience. I rather, I would like to always do that, but unfortunately the harsh reality of commerce won’t let me – I need to craft things that will work for different languages under different character sets (and let’s just ignore the whole left to right and right to left thing!).

Unfortunately, as web development goes, the default for everything is the constrained Latin alphabet, which unfortunately is rather limiting in terms of the number of characters it allows for. And because of the nature of the Internet, unfortunately your home grown little applications seldomnly stick around for your natural language use only! A potential solution to this is of course to embrace multibyte character encodings, with UTF-8 going a long way in establishing itself as the encoding to work with in these situations.

Fantastic. Loads of documentation, lots of caveats to take into account and plenty of work to do.

So how about a little test string for your web development, one that will make sure your web application can handle the concept of Internationalization?

No problem, try this one from Sam Ruby on for size:


There, that should keep you on your developer toes! :)

internationalization many flags of the world flapping in the wind