Embedding Apache fop 2.1 in a Java Servlet

I have an application that uses Apache FOP to create PDF files. Everything works fine, except for the Cyrillic letters in the generated PDF file. As far as I understand, I should lay out the font with the Cyrillic letters with the application.

So, I install the application as follows: I have a configuration file in the file. /src/main/resources/conf/fop.xml (default for PDF rendering) and initialize FOP as follows:

FopFactoryBuilder fopBuilder =
  new FopFactoryBuilder(fileLoader.getFile("conf/fop.xml").toURI(),
    new ClasspathResolverURIAdapter());
fopFactory = fopBuilder.build();

fileLoader is my own file reader utility, XSLT is loaded by it, and everything works fine. I tried other ways to do this, no luck. Fop itself works fine, except for fonts.

In the configuration, I have:

<renderers>
    <renderer mime="application/pdf">
      <filterList>
        <value>flate</value>
      </filterList>
      <fonts>
        <directory recursive="true">./</directory>
        <auto-detect/>
      </fonts>
    </renderer>
  </renderers>

Fonts are in a subdirectory in conf /.

XSLT , , , , , , XSLT .

:

  • fop, , .
  • , , .

, - , - .

+4
1

, , , PDF.

URI FopFactoryBuilder URI, .

- :

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;

...

DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder.buildFromFile(new File("conf/conf.xml"));
FopFactoryBuilder fopFactoryBuilder = new FopFactoryBuilder(new File(".").toURI()).setConfiguration(cfg);
FopFactory fopFactory = fopFactoryBuilder.build();
+1

Source: https://habr.com/ru/post/1684632/


All Articles