Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache FOP | custom fonts | relative URL not working

Tags:

apache-fop

aem

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:

  • embed-url="context:/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf"
  • embed-url="file:/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf"

Working embed-url:

  • embed-url="http://localhost:4503/etc/designs/projectName/clientlibs/pdffonts/Batang.ttf"

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>
like image 761
Rupesh Avatar asked Feb 04 '16 08:02

Rupesh


2 Answers

"Starting point" for relative paths:

  • if the configuration file has a font-base element (as a direct child of the document root element), its value is used to resolve relative font paths
  • otherwise, the value of the base element is used instead
  • the default configuration file included in the distribution has the element <base>.</base>, meaning that relative paths must be interpreted as relative to the position of the configuration file

Note 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:

  • you don't need context: or file:
  • if the embed-url starts with / it's an absolute path, otherwise it's a relative one referring to the "starting point" defined before
  • relative 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)

like image 78
lfurini Avatar answered Nov 14 '22 15:11

lfurini


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"

like image 25
compyutech Avatar answered Nov 14 '22 13:11

compyutech