I'm using the Camel FOP Component version 2.19.1 which brings in the FOP 2.1 dependency. The application must be self-contained - deployable as a fat WAR. or JAR and Dockerized, or run within a Tomcat container. I have the fonts in the "resources" project folder which means Maven will place the font files at the root of my classpath - directly under the /classes folder within the WAR.
My FOP configuration file is loading correctly, and the fonts are found fine if I just place my fonts in a local directory and hardcode the absolute path to them like embed-url="file:///C:/fonts/HelveticaNeueLTStd-Lt.ttf"
. However when I try a relative URL as in embed-url="HelveticaNeueLTStd-Lt.ttf"
an exception is thrown saying "URI is not absolute". This makes little sense, since the FOP documentation states that a relative URI can be used and that's what the <font-base>
is for! Very confusing...
I've tried a lot of things without success over the past few days, such as even replacing file:
in the URI with classpath:
, however unlike the other Apache projects it seems to only support file:
. I've even tried removing my font registration from the config file completely, and just using <auto-detect />
. While it finds all the fonts on my system (in about 5 minutes!) it does not find the font at the root of my classpath. Additionally even if it did work, I'd prefer FOP not to scan every installed system font and attempt to create TEMP cache files because this must be deployable in Docker containers within a cloud environment.
Is what I'm trying to do even possible with the current FOP implementation?
Here is an example of a FOP config file I tried:
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<font-base>./</font-base>
<fonts>
<!-- This of course works -->
<font kerning="yes" embed-url="file:///C:/fonts/HelveticaNeueLTStd-Lt.ttf">
<font-triplet name="Helvetica Neue LT Std" style="normal"
weight="normal" />
</font>
<!-- This results in java.lang.IllegalArgumentException: URI is not absolute -->
<font kerning="yes" embed-url="HelveticaNeueLTStd-Bd.ttf">
<font-triplet name="Helvetica Neue LT Std" style="normal"
weight="bold" />
</font>
<auto-detect />
</fonts>
</renderer>
</renderers>