Mark Stephens FollowMark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Understanding the PDF file Format – Custom font encodings

April 12, 2011 1 min read

One very powerful feature of the PDF file specification is the ability is the option to create custom font encodings. This means that for each font you can choose exactly what glyph value the text index values used in the Tj command map onto. This has a number of advantages, including:-

1. Making it very easy to map font values with subsetted fonts (especially CID fonts). If you are only using a few glyphs in a font, this can substantially reduce the PDF filesize and improve its loading speed.

2. Make it simple to map values from any system/platform so that they display correctly on multiple platforms.

Custom encoding is setup in the /Differences value of the Encoding dictionary. Here is an example

The /BaseEncoding defines the general encoding to use and then the /Differences key lists our changes. It is a number value followed by one or more values (if it is one or more we increment the counter). So [32/space 97/a 99/c/d/e/f 104/h/i 108/l 110/n/o 115/s/t/u 121/y] would define 32 as space, 97 as a, 99 and c, 100 as d, 101 as e, etc. So you can can mix and match standard and non-standard values.

In this case, all the values are glyphs, but they can also be octal, hex or decimal values. Here is an example I found this week in a PDF file.

If the number has a / it is a value, otherwise it is a next glyph number to use which is rather confusing.

You can actually have any value as a glyph (like missing_glyph) but if it is a non-standard one then you need to define it in your font.

So Differences gives you a very powerful way to define custom glyph settings for every font. Have you ever used it?

This post is part of our “Understanding the PDF File Format” series. In each article, we aim to take a specific PDF feature and explain it in simple terms. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!