FO to PDF/a Conversion with Apache FOP Java Library

前端 未结 1 1315
时光说笑
时光说笑 2020-12-21 15:36

I\'m trying to convert .fo files to PDF/a with Apache FOP 2.1 with the exemple code given in the documentation. I managed to convert the hell

1条回答
  •  时光说笑
    2020-12-21 15:58

    I was able to create a PDF/A output using the same example files after a few changes:

    1. in the input FO file, I explicitly added font-family="Helvetica" (or your favourite font family) in a position where it effected all the text

      Without this, even if FOP defaults to using Helvetica when no font-family is set, it apparently is not able to find a configuration for it.

    2. in the configuration file, I mapped the Helvetica font family to an existing font, for example Arial

      
        
      
      
    3. in the Java code, I configured FOP to use my configuration file, and the user agent to enable accessibility

      import org.apache.avalon.framework.configuration.Configuration;
      import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
      import org.apache.fop.apps.FopFactoryBuilder;
      
      ...
      DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
      Configuration cfg = cfgBuilder.buildFromFile(new File("/Users/lfurini/fop.xconf"));
      FopFactoryBuilder fopFactoryBuilder = new FopFactoryBuilder(new File(".").toURI()).setConfiguration(cfg);
      FopFactory fopFactory = fopFactoryBuilder.build();
      
      FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
      // configure foUserAgent as desired
      foUserAgent.setAccessibility(true);
      foUserAgent.getRendererOptions().put("pdf-a-mode", "PDF/A-1b");
      ...
      

    0 讨论(0)
提交回复
热议问题