7

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>
Rupesh
  • 2,627
  • 1
  • 28
  • 42
  • As I was working with AEM, I end up creating multiple configuration files for Apache FOP per run mode. This met my requirement but I guess there must be better way to do this. – Rupesh Feb 04 '16 at 10:06
  • is it possible to import one config to another? i need the same fonts in every config but different pdf-x-mode settings. any idea? – Entara Nov 15 '19 at 10:13

3 Answers3

6

"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)

lfurini
  • 3,729
  • 4
  • 30
  • 48
  • 1
    but it's not a relative path, it's hardcoded path. Relative is when you use contextPath of whole application. Your solution "conflicts with portability". – zond Mar 03 '16 at 09:22
1

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"

compyutech
  • 578
  • 3
  • 8
  • 26
0

For FOP-2.1 there is a patch for "Allow relative paths to font files/directories" at https://issues.apache.org/jira/browse/FOP-2627.