Using Custom Fonts in Lucee

If you are using a font within a PDF you are creating and it's not a standard font already installed on the server, you need to make the source fonts available to Lucee.

When using Lucee 5.2 you need to bundle the font TTF files in with a pd4fonts.properties file to make a file called fonts.jar. Remember, a jar file is just a zip file renamed.

The pd4fonts.properties file maps the font face to the font file. In this example I want to use the Calibri font in my PDF documents. Therefore my pd4fonts.properties file looks like this:

Calibri=Calibri.ttf
Calibri\ Bold=Calibrib.ttf
Calibri\ Italic=Calibrii.ttf
Calibri\ Bold\ Italic=Calibriz.ttf
Calibri\ Light=calibril.ttf
Calibri\ Light\ Italic=calibrili.ttf

There have been some reports that a trailing newline needs to exist at the end of the pd4fonts.properties file.

My fonts.jar contents looks like this:

Calibri.ttf
Calibrib.ttf
Calibrii.ttf
calibril.ttf
calibrili.ttf
Calibriz.ttf
pd4fonts.properties

The fonts.jar file needs to be placed in the WEB-INF/lib/ directory for the Lucee instance. Make sure the file has the same permissions as the existing lucee.jar file in the same location.

Finally you'll need to restart Lucee for the the fonts to be recognised.

References: