Chapter 11. Choosing the right font

 

This chapter covers

  • Font files, types, and classes
  • Writing systems and advanced typography
  • Automatic font creation and selection

We discussed two font classes in chapter 2: Font and BaseFont. You used the Font class in section 2.2.1 for the 14 standard Type 1 fonts. These fonts are supposed to be “known” by every PDF viewer and are therefore never embedded by iText. In section 2.2.2, you used the Font class in combination with BaseFont to embed fonts. You created a BaseFont object by telling iText where to find a font program; for instance, a .ttf file. In chapter 3, you needed the BaseFont class to set the font when writing text to the direct content. You’ve also learned how to measure Strings in a certain font, how to change the render mode, and so on.

You know how to use fonts in your applications, but how do you choose them? Which font files can be used with iText? How about special writing systems? In some languages, you have to write from right to left, and from top to bottom. Furthermore, there are some convenience classes that make it easier to select a font. You’ll find the answers to all these questions in this chapter.

11.1. Getting fonts from a file

Figure 11.1 shows a PDF containing a sentence written nine times using different fonts.

Figure 11.1. One sentence written in different fonts

11.2. Examining font types from a PDF perspective

11.3. Using fonts in iText

11.4. Automating font creation and selection

11.5. Summary

sitemap