问题描述
我想让 Apache FOP 使用 Arial 作为字体.到目前为止,运气不佳.
I am tring to get Apache FOP to use Arial as font. So far, without luck.
在我的 config.xml 中它说:
In my config.xml it says:
<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 字体.
But it doesnt seem to work. When I start FOP on the command line it says font Arial normal not found.
我曾尝试在 FOP 中使用 TTFReader 从 ttf 生成 Arial.xml 文件,但这也没有奏效(即使按照 fop 网页上的说明进行操作).我收到以下错误消息:
I have tried to generate the Arial.xml file from the ttf with TTFReader in FOP but that, too, hasnt worked (even following the instructions on the fop webpage).I get the following error message:
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)
也许我只见树木不见森林,但我不知道该怎么做.
Maybe Im not seeing the forrest for the trees, but I'm at a loss as to what to do.
有什么建议吗?
UDP 日期:
- 我从这个站点下载了很多 xml 文件:http://www.java2s.com/Code/Jar/f/Downloadfopfontmetricsjar.htm(在我看来,它很像 fop 中已经存在的 xml 文件.所以我认为它们的格式正确)
- I downloaded a lot of xml-Files from this site:http://www.java2s.com/Code/Jar/f/Downloadfopfontmetricsjar.htm(which to me look a lot like the xml-files that were already in fop. so I assume they are in the correct format)
我把它们放在文件夹 fop/src/codegen
I put them in the folder fop/src/codegen
我也把 arial.tff 放在那里
I also put the arial.tff there
在文件 fop/conf/xconf 中它说
in the file fop/conf/xconf it says
<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,但我仍然收到诸如字形 xyz 不包含在 Helvetica 中"之类的错误消息.pdf 以 Times New Roman 格式显示...
So ive got auto-detec and specified a directory for the fonts and embedded arial - stil I get error messages like "glyph xyz is not included in Helvetica" although nowhere in my stylesheets does it say font-family Helvetica. The pdfs are displayed in Times New Roman...
++ 更新++
好的...
我的 fop.xconf 文件现在说明:
my fop.xconf file says this now:
<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
I've added font-family="Arial" to pretty much all the elements now :D
我在命令行中进入我的 fop 目录并输入
I go to my fop directory in the command line and enter
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.
不要介意网址.
推荐答案
我遇到了同样的问题,使用 .NET 中的 FopFactory 并使用 Apache doc 上的 java 示例解决了它:http://xmlgraphics.apache.org/fop/1.1/embedding.html#config-external
I had the same Problem, using FopFactory from .NET and solved it whith the java example on the Apache doc:http://xmlgraphics.apache.org/fop/1.1/embedding.html#config-external
我用这个代码创建了一个配置文件:
I created a config file with this code:
<?xml version="1.0" encoding="utf-8" ?>
<fop>
<renderers>
<renderer mime="application/pdf">
<fonts>
<auto-detect/>
</fonts>
</renderer>
</renderers>
</fop>
然后添加它的信息 FopFactory:
Then added it info FopFactory:
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setUserConfig("fop.xconf");
自动检测"选项用于检测系统上的所有字体,这可能需要一段时间并且输出的尺寸很大.要从系统配置特定字体,请参阅上面链接中的文档.
The option "auto-detect" is for detecting all fonts on the system and it may takes a while and the output has a big size.To configure a specific font from the system, see the doc in the link above.
这篇关于将字体嵌入 Apache FOP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!