Unable to show extended characters in a PDF using iText

Adobe’s PDF readers come with 14 standard fonts built-in to the reader software. Most third-party reader offer these too. Not surprisingly iText lets you select the standard fonts and use them in the PDFs you create.

If you are finding that you are not able to display extended characters in your PDFs – and by extended characters I mean characters that are not in the Basic Latin Unicode chart – then this could be because you are using one of the 14 built-in fonts and they do not support the character you want to display.

To find out which characters are in the Basic Latin Unicode, look here: http://unicode.org/charts/

You will need to find a font that supports the characters you want to print. For an open-source replacement for the built-in Times New Roman, Arial or Courier you could try Liberation Fonts. We’ve used the Times Liberation font and it does look a bit different that the built-in but its metric compatible and, in my opinion, looks nicer.

Create PDF files with PHP using FPDF

FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.

FPDF has other advantages: high level functions. Here is a list of its main features:

  • Choice of measure unit, page format and margins
  • Page header and footer management
  • Automatic page break
  • Automatic line break and text justification
  • Image support (JPEG, PNG and GIF)
  • Colors
  • Links
  • TrueType, Type1 and encoding support
  • Page compression

FPDF requires no extension (except zlib to activate compression and GD for GIF support) and works with PHP4 and PHP5.