Custom Fonts in CFDocument

Hello,

I’m creating a PDF using cfdocument, and I’m struggling to include custom fonts in it. I’ve seen a couple threads about this topic and references to the well-done article at:

But, for the life of me, I cannot get this working. My biggest stumbling block, at the moment, is that I don’t see the fonts.jar file that’s mentioned in the above article anywhere in my Lucee install. I’ve also tried downloading full Lucee installs from Download Lucee and searching through the directory structure, but I can’t find fonts.jar there, either.

Does anyone have any suggestions for either tracking down a copy of fonts.jar so that I can add my custom fonts to it, or an alternate method of including my custom fonts in a PDF generated with cfdocument?

I’m on Lucee 5.0.1.85, and it’s running as a Docker container.

Thanks in advance.

This might help:

https://lucee.daemonite.io/t/problem-with-chinese-characters-in-pdf/467/4

Thanks! I found that article in my searches, but somehow missed the reply that you linked to. I downloaded the fonts.jar that was linked and I’m modifying it with my custom font, now.

FYI: we are planning to add a fonts directory where you can put custom fonts and it will use them from there automagically.

Automagic fonts would be fantastic. Any idea when that will be implemented?

No ETA ATM, but you can watch the ticket at
https://luceeserver.atlassian.net/browse/LDEV-1470

Actually, you should vote for it there – the more votes, the higher the priority that the ticket will get.

Done! It now has 2 votes. :slightly_smiling_face:

So, I’ve created my fonts.jar with my custom font and updated pdf4fonts.properties file, but I don’t have an /opt/lucee/lib folder. I do have /opt/lucee/web/lib, but I’ve put my fonts.jar in there and restarted lucee, but my custom fonts still don’t work. I also tried creating /opt/lucee/lib and putting fonts.jar, there. Any suggestions, here? I’ve also triple-checked the contents of my fonts.jar file, and I’m 99% certain they’re correct.

Thanks!

Actually, I think I’ve answered my own question. According to the logs, the copy of fonts.jar I have in /opt/lucee/web/lib is being loaded:
“INFO”,“http-apr-8888-exec-2”,“09/01/2017”,“17:28:23”,“OSGi”,“add bundle:/opt/lucee/web/lib/fonts.jar”
“INFO”,“http-apr-8888-exec-2”,“09/01/2017”,“17:28:23”,“OSGi”,“start bundle:fonts:0.0.0.0”

So, I guess now my issue is in my code? I’ll circle back to this on Tuesday. Thanks again, @21Solutions and @modius, for your help.

Sorry but I didn’t get a chance to read the whole thread here, but see also my comments at:
https://luceeserver.atlassian.net/browse/LDEV-1273

And ask again the specific question please if you still have one.

I’m not sure I have a specific question, at this point. I have, as far as I can tell, followed the instructions meticulously, but I can’t get my fonts to print to a pdf generated by cfdocument.

Here’s what I’ve tried. If anyone can tell me what I’m missing, I would certainly appreciate it.

I downloaded the fonts.jar from Log in with Atlassian account, changed it to a zip, added my .ttf files, updated the pd4fonts.properties files, saved and renamed to fonts.jar.

I verified that the .ttf and .properties file in fonts.jar are in a subfolder named “fonts.”

Here’s a snippet from my pdf4fonts.properties file:

Monotype\ Corsiva=MTCORSVA.TTF
Century\ Gothic=GOTHICBI.TTF

I copied my fonts.jar to /opt/lucee/web/lib (This is a different path than what I’ve seen mentioned in other articles, but it appears to get loaded, according to application.log. I have, at various times, also tried putting my fonts.jar in /opt/lucee/lib, as mentioned in the links, above. But, that path didn’t exist in my lucee install, and I don’t see that fonts.jar get loaded, according to application.log)

After copying the fonts.jar file, I restarted Lucee. In fact, I restarted the whole Docker container.

I’m using the snippet, below, to test my custom font. Note that the Liberation Serif font, which is also included in fonts.jar, works as expected.

I’m really at a loss, here, so any and all suggestions are most welcome.

<cfcontent type="application/pdf">
<cfheader name="Content-Disposition" value="inline; filename=./seatingReport.pdf">
<cfdocument format="PDF" marginbottom="0" marginleft="0" marginright="0" margintop="0"
            orientation="landscape" overwrite="true" unit="in" localurl="true"
            fontembed="true">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <meta charset="UTF-8">
  <style type="text/css">
    @font-face {
      font-family: "Monotype Corsiva";
    }
    @font-face {
      font-family: "Century Gothic";
    }
    @font-face {
      font-family: "Liberation Serif";
    }
  </style>
</head>
<body>
<div>
      <span style="font-family:Monotype Corsiva;">Test</span><br />
      <span style="font-family:Century Gothic;">Test</span><br />
      <span style="font-family:Liberation Serif;">Liberation San</span>
    </div>
</body>
</html>
</cfdocument>

One more detail that I just noticed, today. When I use CFDocument, my custom fonts, Monotype Corsiva and Gothic Century, don’t load. But, the other custom fonts in fonts.jar, Liberation Sans and Liberation Serif, DO load. See screenshot:

But, if I comment out CFDocument and just view my test page as html, my custom fonts DO load but the Liberation fonts DON’T load. What is going on here?

I suspect that there is another copy of a jar with a directory named fonts on your classpath, and that one is used rather than the one that you supplied.

This is probably where you go wrong. The fonts are not loaded by Lucee itself, but by a 3rd party library which loads them from the classpath. Try to put it in the same directory with the other jars of Tomcat, and restart Tomcat.

Thanks for the reply. I’ve never dealt with the classpath and the first article I found on it is a little daunting. I’ll muck around and see what I can find.

It’s very simple:

The classpath is a list of paths (directories/jars) where Java looks for when it tries to load a class or some other resource in the classic Java way (as opposed to OSGi).

You can put your fonts jar file next to the Lucee jar or next to the Tomcat (assuming you’re using Tomcat) jars which resides by default at {Tomcat}/lib. Then restart Tomcat/Lucee.

1 Like

Thanks. That’s much more straightforward than the article I was looking at: https://www.mulesoft.com/tcat/tomcat-classpath

I’ll give it a try when things slow down, here.

Looking for a Custom Fonts in CFDocument, after reading this Topic, I found a new CFDocument new option “fontdirectory”. This can be a folder mapped to Lucee Admin.
More info here <cfdocument> :: Lucee Documentation
Great!
D

1 Like