FO to PDF/a Conversion with Apache FOP Java Library

℡╲_俬逩灬. 提交于 2019-11-29 17:30:15

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

    <font kerning="yes" embed-url="/Library/Fonts/arial.ttf">
      <font-triplet name="Helvetica" style="normal" weight="normal"/>
    </font>
    
  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");
    ...
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!