cancel
Showing results for 
Search instead for 
Did you mean: 

FOP configuration - path to custom fonts

Former Member
0 Kudos
1,114

Hi all,

I am using FOP to generate a PDF file. I need to use some custom fonts, so I followed this guide to tell FOP where on the disk to find them.

The guide works perfectly on a standalone FOP instance, while I am not able to replicate the same behavior on the Hybris embedded version, due to a problem with relative paths. It seems that no matter what I configure, I am not able to reach my fonts using a relative path, either to the Hybris bin dir, the fop configuration file dir, the fop lib dir, etc...

The Apache guide says:

Relative URIs for those properties are evaluated relative to the base URI of the configuration file. If the configuration is provided programmatically, the base URI can be set with FopFactory.setUserConfigBaseURI ; default is the current working directory.

I tried different configurations for the fopconfig.xml file; I also tried to customize the fop.config.xml property inside project.properties, with no luck.

The only working configuration is the following:

 <fop version="1.0">
   <strict-validation>false</strict-validation>
   <renderers>
     <renderer mime="application/pdf">
       <fonts>
         <directory>ABSOLUTE_PATH_TO_MY_HYBRIS_BIN_DIR/platform/ext/commons/resources/commons/config/fonts/</directory>
         <autodetect/>
       </fonts>
     </renderer>
   </renderers>
 </fop>

But of course I don't want to use an absolute path.

Could someone help me?

Thank you Francesco

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Ok, I found a possible solution: for some reason, the current working directory for FOP is somewhere two levels above the "platform" folder. I realized that because the following configuration works:

 <fop version="1.0">
   <strict-validation>false</strict-validation>
   <renderers>
     <renderer mime="application/pdf">
       <fonts>
         <directory recursive="true">../../</directory>
         <autodetect/>
       </fonts>
     </renderer>
   </renderers>
 </fop>

After a little bit more investigation, I found the solution:

 <fop version="1.0">
   <strict-validation>false</strict-validation>
   <renderers>
     <renderer mime="application/pdf">
       <fonts>
         <directory>../../ext/commons/resources/commons/config/fonts/</directory>
         <autodetect/>
       </fonts>
     </renderer>
   </renderers>
 </fop>

So basically, the "../../" brings you two levels under to the platform folder, then you can continue your path as you wish. What the CWD is remains a mystery... :-)