iText pdf library
Website search

Why aren't my fonts getting registered?

I have a program using iTextSharp that includes the code


foreach (string fontname in FontFactory.RegisteredFonts) {
   Log.Info("**** Found registered font: " + fontname);
When I run it (using Mono on a CentOS box), the log shows only the core PostScript fonts:
  • zapfdingbats
  • times-roman
  • times-italic
  • helvetica-boldoblique
  • courier-boldoblique
  • helvetica-bold
  • helvetica
  • courier-oblique
  • helvetica-oblique
  • courier-bold
  • times-bolditalic
  • courier
  • times-bold
  • symbol

But I have 156 TTF files under my /usr/share/fonts directory tree (which is one of the directories mentioned in the code for the RegisterDirectories function). Why aren't these being registered?

Posted on StackOverflow on Nov 29, 2013 by dan04

There are subtle differences between iText and iTextSharp.

In iText, registerDirectories() looks like this:

public int registerDirectories() {
    int count = 0;
    String windir = System.getenv("windir");
    String fileseparator = System.getProperty("file.separator");
    if (windir != null && fileseparator != null) {
        count += registerDirectory(windir + fileseparator + "fonts");
    count += registerDirectory("/usr/share/X11/fonts", true);
    count += registerDirectory("/usr/X/lib/X11/fonts", true);
    count += registerDirectory("/usr/openwin/lib/X11/fonts", true);
    count += registerDirectory("/usr/share/fonts", true);
    count += registerDirectory("/usr/X11R6/lib/X11/fonts", true);
    count += registerDirectory("/Library/Fonts");
    count += registerDirectory("/System/Library/Fonts");
    return count;

In iTextSharp however, the method looks like this:

public virtual int RegisterDirectories() {
    string dir = Path.Combine(
            Environment.SpecialFolder.System)), "Fonts");
    return RegisterDirectory(dir);

Java is platform independent, so we have to look for the 'usual suspects'. C# is Windows specific, so we can depend on the environment to tell us where to find fonts. Your question tells us that Mono doesn't support this, so you'll have to use FontFactory.RegisterDirectory("/usr/share/fonts");

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now