Chapter 4. Text
In this chapter you will learn how to draw text on a page. Drawing text is the most complex part of PDF graphics, but it is also what helped PDF beat its competitors to become the international standard that it is today. While the other original players converted text to raster images or vector paths (to maintain the visual integrity), the inventors of PDF knew that users needed text that could be searched and copied and didn’t just look pretty on the screen. With the depth of experience and understanding of fonts that Adobe’s engineers had, they were able to integrate actual text with visual presentation.
While the text support in PDF enables the rendering of any glyphs from any font representing any language, the mechanics (as you’ll see shortly) were all created prior to Unicode. This means that many things that developers working in other file formats take for granted, such as just putting down Unicode codepoints and letting the renderer do all the hard work, have to be done manually with PDF.
Now that you’ve been given fair warning, let’s start!
Fonts
In the previous chapters you learned how to draw vector graphics (or paths) as well as raster graphics (images) on a page. These types of drawing operations are fairly simple as they don’t normally need extra information—it’s just the instructions and (in the case of raster images) the image data. Text, however, requires more pieces. The most important of these pieces is the font.
Glyphs
A font, sometimes called a