最初我是这样创建我的FopFactory:
FopFactory.newInstance(new File("config/pdf/fop.xconf"))
在我的配置文件中选择了所有自定义配置。但是,我的要求已经改变,我需要使用FopFactoryBuilder来构建我的FopFactory(它不会将配置文件作为参数)。
FopFactoryBuilder builder = new FopFactoryBuilder(URI.create("/"), uriResolverAdapter);
Configuration configuration = new DefaultConfiguration("config/pdf/fop.xconf");
builder.setConfiguration(configuration);
但是,这似乎不起作用。我特别需要包含一些与字体相关的东西:
<fonts>
<auto-detect/>
<font-base>./</font-base>
<directory recursive="true">config/pdf/fonts</directory>
</fonts>
修改
我也试过这个,
DefaultConfigurationBuilder defaultConfigurationBuilder = new DefaultConfigurationBuilder();
builder.setConfiguration(defaultConfigurationBuilder.build("config/pdf/fop.xconf"));
以及
builder.setConfiguration(defaultConfigurationBuilder.buildFromFile(new File("config/pdf/fop.xconf")));
此,
FileInputStream config = new FileInputStream(new File("config/pdf/fop.xconf"));
builder.setConfiguration(defaultConfigurationBuilder.build(config));
此,
builder.setConfiguration(defaultConfigurationBuilder.buildFromFile("config/pdf/fop.xconf"));
最后这个(Jars.getJarFile只获取正在运行的jar的文件):
File jarFile = Jars.getJarFile(this);
if (jarFile!= null) {
String absoluteLocation = jarFile.getParent() + "/config/pdf/fop.xconf";
builder.setConfiguration(defaultConfigurationBuilder.buildFromFile(absoluteLocation));
}
但是当我用FopFactory创建一个新的fop时,这些都给了我一个例外:
java.lang.IllegalArgumentException: URI is not absolute
答案 0 :(得分:2)
我最终做的是创建这样的配置:
File.WriteAllLines
并从我的配置中删除以下行:
DefaultConfigurationBuilder defaultConfigurationBuilder = new DefaultConfigurationBuilder();
builder.setConfiguration(defaultConfigurationBuilder.build("config/pdf/fop.xconf"));