我想让 Apache FOP 使用 Arial 作为字体。到目前为止,没有运气。
在我的 config.xml 中它说:
<fonts>
<font kerning="yes" embed-url="file:///C:/Windows/Fonts/Arial.ttf" encoding-mode="auto">>
<font-triplet name="Arial" style="normal" weight="normal"/>
</font>
</fonts>
但它似乎不起作用。当我在命令行上启动 FOP 时,它说字体 Arial normal not found。
我曾尝试在 FOP 中使用 TTFReader 从 ttf 生成 Arial.xml 文件,但这也没有奏效(即使按照 fop 网页上的说明进行操作)。我收到以下错误消息:
C:\Users\xy\Desktop\FOP2>java -cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.0.4.jar;lib\commons-io-1.3.1.jar org.apache.fop.TTFReader C:\Windows\Fonts\arial.ttf Arial.xml
TTF Reader for Apache FOP 1.1
Parsing font...
Reading C:\Windows\Fonts\arial.ttf...
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlgraphics/fonts/Glyphs
at org.apache.fop.fonts.truetype.TTFFile.initAnsiWidths(TTFFile.java:662)
at org.apache.fop.fonts.truetype.TTFFile.readFont(TTFFile.java:711)
at org.apache.fop.fonts.apps.TTFReader.loadTTF(TTFReader.java:224)
at org.apache.fop.fonts.apps.TTFReader.main(TTFReader.java:177)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlgraphics.fonts.Glyphs
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
也许我没有看到森林的森林,但我不知道该怎么做。
有什么建议么?
更新日期:
- 我从这个站点下载了很多 xml 文件: http ://www.java2s.com/Code/Jar/f/Downloadfopfontmetricsjar.htm (在我看来很像已经在 fop 中的 xml 文件。所以我认为它们的格式正确)
我把它们放在文件夹 fop/src/codegen
我也把 arial.tff 放在那里
在文件 fop/conf/xconf 它说
<fonts>
<directory>C:\Windows\Fonts</directory>
<!-- embedded fonts -->
<!--
This information must exactly match the font specified
in the fo file. Otherwise it will use a default font.
For example,
<fo:inline font-family="Arial" font-weight="bold" font-style="normal">
Arial-normal-normal font
</fo:inline>
for the font triplet specified by:
<font-triplet name="Arial" style="normal" weight="bold"/>
If you do not want to embed the font in the pdf document
then do not include the "embed-url" attribute.
The font will be needed where the document is viewed
for it to be displayed properly.
possible styles: normal | italic | oblique | backslant
possible weights: normal | bold | 100 | 200 | 300 | 400
| 500 | 600 | 700 | 800 | 900
(normal = 400, bold = 700)
-->
<font metrics-url="C:\Users\z003a5bp\Desktop\FOP2\src\codegen\fonts\arial.xml" kerning="yes" embed-url="C:\Users\z003a5bp\Desktop\FOP2\src\codegen\fonts\arial.ttf">
<font-triplet name="Arial" style="normal" weight="normal"/>
<!-- <font-triplet name="ArialMT" style="normal" weight="normal"/> -->
</font>
<!-- <font metrics-url="arialb.xml" kerning="yes" embed-url="arialb.ttf">
<font-triplet name="Arial" style="normal" weight="bold"/>
<font-triplet name="ArialMT" style="normal" weight="bold"/> -->
<auto-detect/>
</fonts>
所以我得到了自动检测并为字体和嵌入的 arial 指定了一个目录——尽管我的样式表中没有任何地方说字体系列 Helvetica,但我仍然收到诸如“glyph xyz 不包含在 Helvetica 中”之类的错误消息。pdf 以 Times New Roman 格式显示...
++更新++
好的...
我的 fop.xconf 文件现在这样说:
<fop version="1.0">
<base>.</base>
<source-resolution>72</source-resolution>
<target-resolution>72</target-resolution>
<default-page-settings height="11in" width="8.26in"/>
<renderers>
<renderer mime="application/pdf">
<filterList>
<value>flate</value>
</filterList>
<fonts>
<font metrics-url="file:///C:/Users/z003a5bp/Desktop/FOP2/src/codegen/fonts/arial.xml"
kerning="yes"
embed-url="file:///C:/Users/z003a5bp/Desktop/FOP2/arial.ttf">
<font-triplet name="Arial" style="normal" weight="normal"/>
</font>
<auto-detect/>
</fonts>
</renderer>
我现在几乎所有元素都添加了 font-family="Arial" :D
我在命令行中转到我的 fop 目录并输入
fop -xml blabla\file.xml -xsl blabla\stylesheet.xsl -pdf output.pdf
我得到以下信息:
Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
Schwerwiegend: Image not found. URI: 15300145419.PNG. (See position 44:-1)
Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
Warnung: The following feature isn't implemented by Apache FOP, yet: table-layout="auto" (on fo:table) (Siehe Position 29:-1)
Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
Schwerwiegend: Image not found. URI: 15627351051.PNG. (See position 44:-1)
Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
Schwerwiegend: Image not found. URI: 15629782795.PNG. (See position 44:-1)
Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
Warnung: Font "Arial,normal,400" not found. Substituting with "any,normal,400".
Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
Warnung: Glyph "?" (0x95) not available in font "Times-Roman".
Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
Warnung: Font "Arial,italic,400" not found. Substituting with "any,italic,400".
Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
Warnung: Content overflows the viewport of the fo:region-before on page 1 in block-progression direction by 2989 millipoints. (See position 50:-1)
Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
Information: Rendered page #1.
Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
Warnung: Content overflows the viewport of the fo:region-before on page 2 in block-progression direction by 2989 millipoints. (See position 59:-1)
Nov 07, 2013 1:34:29 PM org.apache.fop.events.LoggingEventListener processEvent
Information: Rendered page #2.
不要介意网址。