我成功地使用嵌入Java應用程序中的Apache FOP 1.1將XML轉換爲PDF。不幸的是,我已被指示降級到FOP 1.0以符合公司許可。所以,我用1.1 jar替換了1.0 jar,並且爲了兼容性而交叉檢查了依賴jar。一切正常,程序運行良好。然而,FOP 1.0生成的PDF只包含「#」對於存在錯誤的每個字符:FOP 1.0交換FOP 1.1後Apache FOP丟失字形
Glyph "M" (0x4d, M) not available in font "Helvetica".
(在這裏,「M」僅作爲一個例子,但它表明這個錯誤對文件中的每個字符)。我已經看過了這個錯誤的Apache網站,其中規定:
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的網站的例子,這是相當簡單的
//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網站的例子,達到同樣的效果:
<?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設置不同的字體爲FONT-FAMILY值:FO
我我不清楚我錯過了什麼。我一直在搜索Apache網站和谷歌FOP 1.0和FOP 1.1之間的變化,這將是相對於此,但無濟於事。有人有主意嗎?