关于Java:将FOP 1.1交换为FOP 1.0后,Apache FOP缺少字形

Apache FOP missing glyphs after exchanging FOP 1.1 for FOP 1.0

我使用嵌入在Java应用程序中的Apache FOP 1.1成功地将XML转换为PDF。不幸的是,我被指示降级到FOP 1.0以符合公司许可。因此,我用1.1个jar替换了1.0个jar,并交叉检查了依赖jar的兼容性。一切正常,程序运行正常。但是,FOP 1.0生成的PDF对于每个字符仅包含"#",错误为:

1
Glyph"M" (0x4d, M) not available in font"Helvetica".

(这里," M"仅用作示例。但是它显示了文件中每个字符的错误。)我在Apache网站上查找了此错误,该错误指出:

1
If no glyph can be found for a given character, FOP will issue a warning and use the glpyh for"#" (if available) instead.

我发现这很奇怪,因为此代码对于FOP 1.1正常工作,并且我使用的是基本的字母数字字符。 (即,即使" Hello World"也无法正确打印"。)我的转换代码基于Apache网站上的示例,并且非常简单

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Constructs a fop with desired output format and user settings
Fop fop = fopFactory.newFop("application/pdf", agent, out);

//Setup JAXP using identity transformer direct from XSLT:FO output template
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(new StringReader(xslfoReceiptLayout))); // identity transformer

//Setup input stream from XML string
Source src = new StreamSource(new StringReader(receiptXml));

//Resulting SAX events msut be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());

//Start XSLT transformation and FOP processing
transformer.transform(src, res);

logger.debug("Finished XML to PDF conversion");

其中xslfoReceiptLayout是包含我的xslfo数据的字符串。我尝试将这些数据简化为来自W3站点的示例,以达到相同的效果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="UTF-8"?>

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

<fo:layout-master-set>
  <fo:simple-page-master master-name="A4">
    <fo:region-body />
  </fo:simple-page-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="A4">
  <fo:flow flow-name="xsl-region-body">
    <fo:block>Hello W3Schools</fo:block>
  </fo:flow>
</fo:page-sequence>

</fo:root>

我尝试过的事情:

  • 使用配置文件手动配置字体以自动检测系统字体
  • 将字体基本目录设置为系统字体目录
  • 在xsl:fo中为字体系列值设置不同的字体

我不清楚我缺少什么。我一直在Apache网站和google上搜索FOP 1.0和FOP 1.1之间的相对于此的更改,但无济于事。有人有什么主意吗?


我从我们公司的资产管理器站点中找到了FOP 1.0 jar的预编译版本,看来已经解决了该问题。不知道从Apache站点获取的源代码中的我的1.0构建在哪里出错。我最好的猜测是预编译版本包含Apache源代码所没有的自包含字体。