107
PDFBox Working with Fonts
In PDFBox, there might be a need to add text with different font family and size. The PDFBox specification states that “The standard set of 14 fonts will always be available in working with PDF documents”. In PDFBox, these set of 14 fonts are defined as constants in the PDType1Font class. A Font is loaded from a file by using PDType1Font API. PDFBox supports the following fonts-
Standard Font | Discription |
---|---|
PDType1Font.TIMES_ROMAN | Times regular |
PDType1Font.TIMES_BOLD | Times bold |
PDType1Font.TIMES_ITALIC | Times italic |
PDType1Font.TIMES_BOLD_ITALIC | Times bold italic |
PDType1Font.HELVETICA | Helvetica regular |
PDType1Font.HELVETICA_BOLD | Helvetica bold |
PDType1Font.HELVETICA_OBLIQUE | Helvetica italic |
PDType1Font.HELVETICA_BOLD_OBLIQUE | Helvetica bold italic |
PDType1Font.COURIER | Courier |
PDType1Font.COURIER_BOLD | Courier bold |
PDType1Font.COURIER_OBLIQUE | Courier italic |
PDType1Font.COURIER_BOLD_OBLIQUE | Courier bold italic |
PDType1Font.SYMBOL | Symbol Set |
PDType1Font.ZAPF_DINGBATS | Dingbat Typeface |
We can configured font for text by using setFont API available on Content Stream.
Example
This example creates a new document and prints the text “Hello World!!!” using one of the PDF base Font.
Output:
After successful execution of the above program, open the PDF Document which shows the following output.
Next TopicPDFBox Working with Attachments