I'm generating PDF file from xml and xsl-fo using Fop-2.1 and spent a lot of time to configure fop configuration file(I'm using cyrillic fonts), in according with https://xmlgraphics.apache.org/fop/2.1/configuration.html
tested it within command-line, it works fine:
fop -c conf.xml -xml xml -xsl xsl -pdf pdf
Next i need to do same in java web application. Application is multi-module Maven project.
I got stuck when tried to get FopFactory instance with my configuration file located in resources folder of service module, here is a project tree
service-module
src/main/resources
conf/config.xml
web-module
How to create instance of FopFactory with my configuration file?
First i did this:
FopFactory fopFactory = fopFactory = FopFactory.newInstance(
new File("/full/path/../resources/conf/config.xml"));
in this a project we using EJB container, and of course
An enterprise bean must not use the java.io package to attempt to access files and directories in the file system.
then I'm trying this one
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = null;
try {
cfg = cfgBuilder.build(getClass().getClassLoader().getResourceAsStream("conf/config.xml"));
} catch (Exception e) {
e.printStackTrace();
}
FopFactoryBuilder factoryBuilder = new FopFactoryBuilder(URI.create("/")).setConfiguration(cfg);
FopFactory fopFactory = factoryBuilder.build();
PDF generating app located in service module. What should i need to set in baseURI?
fopFactoryBuilder = new FopFactoryBuilder(baseURI).setConfiguration(cfg);