Skip to content

Apache FOP embedded remote fonts

I’m using Apache FOP v2.1 embedded in a Java program. I’m trying to retrieve a remote font using a configuration file similar to the following:

<?xml version="1.0"?>
<fop version="1.0">
    <renderer mime="application/pdf">
            <font kerning="yes"
                  embed-url="http://localhost:8000/MyFont.ttf" embedding-mode="subset">
                <font-triplet name="MyFont" style="normal" weight="normal"/>

However, when I run the application to generate a PDF file from XML and XSL files it gives me an error:

java.lang.IllegalArgumentException: URI scheme is not "file"
at org.apache.fop.fonts.FontCache.addFont(
at org.apache.fop.fonts.DefaultFontConfigurator.getFontInfo(
at org.apache.fop.fonts.DefaultFontConfigurator.addFonts(
at org.apache.fop.fonts.DefaultFontConfigurator.configure(
at org.apache.fop.render.PrintRendererConfigurator.getCustomFontCollection(
at org.apache.fop.render.PrintRendererConfigurator.setupFontInfo(
at org.apache.fop.render.intermediate.IFUtil.setupFonts(
at org.apache.fop.render.intermediate.IFRenderer.setupFontInfo(
at org.apache.fop.area.RenderPagesModel.<init>(
at org.apache.fop.area.AreaTreeHandler.setupModel(
at org.apache.fop.area.AreaTreeHandler.<init>(
at org.apache.fop.render.RendererFactory.createFOEventHandler(
at org.apache.fop.apps.Fop.createDefaultHandler(
at org.apache.fop.apps.Fop.<init>(
at org.apache.fop.apps.FOUserAgent.newFop(
at org.apache.fop.apps.FopFactory.newFop(
at com.example.myapp.myFunction(

By checking the source code of FOP I discovered that FOP is trying to add the font to a cache. However, because the font URI is an HTTP URL, when it tries to pass the URL to a java File object, it gives me the error “URI scheme is not file”.

Is there any step I’m missing to load a remote font?


The problem was the FontCache. It uses File Java class to read the content, and since the configuration file contains URL of http(s) protocol, it throws the mentioned exception. To solve the issue, you need to disable the font cache like this:

// load the config file with fonts from remote resources (HTTP)
File configFileWithRemoteFontUrl = new File("fop-config.xconf");

// create a factory instance and disable the font cache
FopFactory factory = FopFactory.newInstance(configFileWithRemoteFontUrl);

// your code as usual...

By disabling the font cache your remote fonts should be loaded fine without aditional configuration.