You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Gerry <ge...@telus.com> on 2017/08/09 18:57:04 UTC

Configuring for Fonts included within a Spring-Boot/Camel Microservice

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?




--
View this message in context: http://apache-fop.1065347.n5.nabble.com/Configuring-for-Fonts-included-within-a-Spring-Boot-Camel-Microservice-tp45367.html
Sent from the FOP - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Configuring for Fonts included within a Spring-Boot/Camel Microservice

Posted by Eduard Tibet <ed...@gmail.com>.
Gerry,

Several years ago I had the same problems with relative paths of font
files on webapps with fop jar included (it was Apache Cocoon with FOP
block and FOP jar).

I experimenting alot but no success. Digging into the logs shows me
very interesting thing, that for some reasons FOP within WAR required
some fake dir to be existent within font-base.

It is a very weird behavior, but anyway, I fixed this with the
following. Try to repeat it step by step:

1. Put fop fonts files and fop conf under resources folder as the following:
- fop.conf
- fop-fonts/fop-fonts-glyphs/<font files are here>

2. Add the following snippet in fop.conf (note about "fake" folder!):
<font-base>fop-fonts/fake</font-base>

3. Add the following snippet to fop.conf in <renderer
mime="application/pdf"> section:

<font kerning="yes" embed-url="fop-fonts-glyphs/liberation-sans-italic.ttf">
        ...any font - glyph combination here - see below sample...
          <font-triplet name="sans-serif" style="normal" weight="normal"/>
    </font>
4. Try to run your app.

So the full path would be wrong from logic point of view
(fop-fonts/fake/fop-fonts-glyphs/liberation-sans-italic.ttf), but it
works for some reasons! Of course, you can remove "fop-fonts-glyphs"
dir respectively in step 1 and 3 to get
fop-fonts/fake/liberation-sans-italic.ttf , but DON'T remove the
mentioning the "fake" dir in font-base

P.S. If you use standalone FOP this tricky stuff is not needed and all
works as should be.

After trying, let me know. If this behavior will be confirmed by you,
it is the reason to file a bug in FOP BTS.

--
regards,
 ET

2017-08-09 21:57 GMT+03:00 Gerry <ge...@telus.com>:
> 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?
>
>
>
>
> --
> View this message in context: http://apache-fop.1065347.n5.nabble.com/Configuring-for-Fonts-included-within-a-Spring-Boot-Camel-Microservice-tp45367.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org