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);
The FOP configuration file is an XML file containing a variety of settings that are useful for controlling FOP's behavior, and for helping it find resources that you wish it to use. The easiest way to get started using a FOP configuration file is to copy the sample found at {fop-dir}/conf/fop.
Factory class which instantiates new Fop and FOUserAgent instances. This class also holds environmental information and configuration used by FOP. Information that may potentially be different for each rendering run can be found and managed in the FOUserAgent. Constructor Summary. protected.
The triplet refers to the unique combination of name, weight, and style for each variation of the font.
I bumped into a similar problem and created a working demo which
Here it is:
https://github.com/riskop/fop_test
See also this:
Set FopFactoryBuilder baseURI to jar classpath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With