TrueType fonts can be used by creating a TrueTypeFont object, specifying the path to the TrueType font file in the constructor. You can then use that font anywhere a font is specified, such as in the constructors of the Label and TextArea classes.
[Java]
// Create a TrueType font class.
TrueTypeFont trueTypeFont = new TrueTypeFont("verdana.ttf");
// Use the TrueType font in a text area Page Element.
page1.getElements().add(new TextArea("Text", 0, 0, 200, 12, trueTypeFont, 12));
Only the characters of a TrueType font that are used are embedded in the PDF document. This greatly reduces the size of the resulting PDF.
NOTE: Helvetica is equivalent to the Arial TrueType font included on Windows systems, and Times is equivalent to the Times New Roman TrueType font included on Windows systems. It is much more efficient to use the equivalent core fonts whenever possible.
TrueType Font Reuse
When using the same TrueType font many times within the same document, it is important to create the TrueTypeFont object only once, and use it whereever needed. Doing this will prevent the font from being embedded in the document multiple times.
When a TrueTypeFont object is initialized, resources are required to parse the font. For fonts that are to be used across multiple documents, the TrueTypeFont class can be initialized and set to a static member variable. This static member variable can then be used anywhere the font is required.
| See Also |
TrueTypeFont Class | Label Class | TextArea Class | Performance Considerations | Fonts And Text | com.cete.dynamicpdf.text Package | Programming with Generator for Java

