PDFBox - PDF Fonts
Standard 14 Fonts
The PDF specification states that a standard set of 14 fonts will always be available when consuming PDF documents. In PDFBox these are defined as constants in the PDType1Font class.
Standard Font |
---|
PDType1Font.TIMES_ROMAN |
PDType1Font.TIMES_BOLD |
PDType1Font.TIMES_ITALIC |
PDType1Font.TIMES_BOLD_ITALIC |
PDType1Font.HELVETICA |
PDType1Font.HELVETICA_BOLD |
PDType1Font.HELVETICA_OBLIQUE |
PDType1Font.HELVETICA_BOLD_OBLIQUE |
PDType1Font.COURIER |
PDType1Font.COURIER_BOLD |
PDType1Font.COURIER_OBLIQUE |
PDType1Font.COURIER_BOLD_OBLIQUE |
PDType1Font.SYMBOL |
PDType1Font.ZAPF_DINGBATS |
TrueType Fonts
Embedding TrueType Fonts
PDFBox supports embedding TrueType fonts. Loading a new font is easy.
PDDocument doc = PDDocument.load( ... ); PDFont font = PDTrueTypeFont.loadTTF( doc, new File( "SpecialFont.ttf" ) );
External TrueType Fonts
While it is recommended to embed all fonts for greatest portability not all PDF producer applications
will do this. When displaying a PDF it is necessary to find an external font to use.
PDFBox will look for a mapping file to use when substituting fonts.
PDFBox will load Resources/PDFBox_External_Fonts.properties off of the classpath to map
font names to TTF font files. The UNKNOWN_FONT property in that file will tell PDFBox which font
to use when no mapping exists.