I have got configuration file to load custom fonts for Apache FOP. I am struggling to configure embed-url on server so that font url changes as per server domain.
I have tried embed-url property value as:
Non working embed-urls:
Working embed-url:
Somehow I can't seems to find proper syntax here. I am using FOP with AEM 6.0.
<?xml version="1.0"?>
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<fonts>
<font kerning="yes"
embed-url="context:/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf" -- this doesn't
embedding-mode="subset">
<font-triplet name="SimSun" style="normal" weight="normal" />
</font>
<font kerning="yes"
embed-url="file:/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf" -- this doesn't
embedding-mode="subset">
<font-triplet name="Batang" style="normal" weight="normal" />
</font>
<font kerning="yes"
embed-url="http://localhost:4503/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf" -- this works
embedding-mode="subset">
<font-triplet name="Batang" style="normal" weight="normal" />
</font>
</fonts>
</renderer>
</renderers>
</fop>
"Starting point" for relative paths:
font-base
element (as a direct child of the document root element), its value is used to resolve relative font pathsbase
element is used instead<base>.</base>
, meaning that relative paths must be interpreted as relative to the position of the configuration fileNote that the values of font-base
and base
can be relative too, in which case they refer to the configuration file path.
<?xml version="1.0"?>
<fop version="1.0">
<base>.</base>
<font-base>/Users/lfurini/Library/Fonts</font-base>
<!-- other possible examples:
<font-base>.</font-base>
<font-base>../fonts</font-base>
-->
<!-- ... -->
</fop>
Relative paths syntax:
context:
or file:
embed-url
starts with /
it's an absolute path, otherwise it's a relative one referring to the "starting point" defined beforerelative paths can contain ../
to go back up in the folder hierarchy, if needed
<!-- directly in the base folder -->
<font kerning="yes" embed-url="font1.ttf">
<font-triplet name="font1" style="normal" weight="normal"/>
</font>
<!-- in a "sister" folder -->
<font kerning="yes" embed-url="../otherFonts/font2.ttf">
<font-triplet name="font2" style="normal" weight="normal"/>
</font>
<!-- in a sub-folder -->
<font kerning="yes" embed-url="specialFonts/font3.ttf">
<font-triplet name="font3" style="normal" weight="normal"/>
</font>
<!-- absolute path -->
<font kerning="yes" embed-url="/Users/lfurini/Library/Fonts/font4.ttf" embedding-mode="subset">
<font-triplet name="font4" style="normal" weight="normal"/>
</font>
(tested with FOP 1.1, 2.0 and 2.1)
(disclosure: I'm a FOP developer, though not very active nowadays)
I solved it by adding full path upto application from code. and added later patr from config file.
fopFactory.setBaseURL(this.getServletContext().getInitParameter("my_path"));
In config
embed-url="fonts/newfont.ttf"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With