本文介绍了将字体嵌入到Apache FOP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算让Apache FOP使用Arial作为字体。到目前为止,没有运气。

在我的config.xml中,它说:

 <字体> 
< / font>
< / fonts>

但它似乎不起作用。当我在命令行启动FOP时,它说Arial字体没有找到。

我试图用TTFReader在FOP中生成ttf的Arial.xml文件,但是也没有工作(甚至按照fop网页上的说明)。
我收到以下错误消息:

$ $ $ $ $ $ code用户\\\\\\\桌面\\ 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

解析字体...
读取C :\Windows\Fonts\arial.ttf ...
线程main中的异常java.lang.NoClassDefFoundError:org / apache / xmlgraphics / fonts / Glyph
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)
引起:java.lang .ClassNotFoundException:org.apache.xmlgraphics.fonts.Glyphs $ b $ java.net.URLClassLoader $ 1.run(Un (原始方法)
at java.net.URLClassLoader $ 1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown来源)
在java.lang.ClassLoader.loadClass(未知源)
在sun.misc.Launcher $ AppClassLoader.loadClass(未知源)$ b $在java.lang.ClassLoader.loadClass(未知来源)

也许我没有看到这些树的福音,但我对什么建议?



UDPDATE:




  • 我从这个网站下载了很多xml文件:

    (这对我来说很像已经是xml文件在fop。所以我假设他们是在正确的格式)


    我把它们放在文件夹fop / src / codegen



    我也把arial.tff放在文件fop / conf / xconf中,它说



     < fonts> 

    < directory> C:\ Windows \ Fonts< / directory>
    此信息必须与fo文件中指定的
    字体完全一致。否则,它将使用默认的字体。

    例如,
    Arial-normal-normal字体
    < / fo:inline>
    指定的字体三元组:

    如果您不想在pdf文档
    中嵌入字体,则不要包含embed-url属性。
    在文档被查看
    的情况下,字体将被正确显示。

    可能的风格:normal |斜体|倾斜| backslant
    可能的权重:normal |粗体| 100 | 200 | 300 | 400
    | 500 | 600 | 700 | 800 | 900
    (正常= 400,粗体= 700)
    - >

    <! - < font-triplet name =ArialMTstyle =normalweight =normal/> - >
    < / font>
    <! - < font metrics-url =arialb.xmlkerning =yesembed-url =arialb.ttf>
    < font-triplet name =ArialMTstyle =normalweight =bold/> - >

    < auto-detect />
    < / fonts>

    所以我得到了自动检测并为字体和嵌入式字体指定了一个目录 - stil出错消息像字型xyz不包括在Helvetica,虽然在我的样式表没有它说字体家庭Helvetica。 PDF格式显示在Times New Roman ...

    ++更新++



    好的...



    我的fop.xconf文件现在说:

     < fop version =1.0> 

    < base>。< / base>

    < source-resolution> 72< / source-resolution>
    <目标分辨率> 72< /目标分辨率>
    < default-page-settings height =11inwidth =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>

    < auto-detect />
    < / fonts>

    < /渲染器>

    现在我已经添加了font-family =Arial几乎所有的元素:D



    我在命令行进入我的fop目录并输入

      fop -xml blabla\file.xml -xsl blabla\stylesheet.xsl -pdf output.pdf 

    我得到以下内容:

      2013年11月7日下午1:34:29 org.apache.fop.events.LoggingEventListener processEvent 
    Schwerwiegend:找不到图像。 URI:15300145419.PNG。 (请参阅位置44:-1)
    2013年11月7日下午1:34:29 org.apache.fop.events.LoggingEventListener processEvent
    Warnung:以下功能尚未由Apache FOP实现:table-layout =auto(在fo:table)(Siehe位置29:-1)
    2013年11月7日下午1:34:29 org.apache.fop.events.LoggingEventListener processEvent
    Schwerwiegend:图片未找到。 URI:15627351051.PNG。 (见位置44:-1)
    2013年11月7日下午1:34:29 org.apache.fop.events.LoggingEventListener processEvent
    Schwerwiegend:Image not found。 URI:15629782795.PNG。 (见位置44:-1)
    2013年11月7日下午1:34:29 org.apache.fop.events.LoggingEventListener processEvent
    Warnung:未找到字体Arial,normal,400。用任何,正常,400代替。
    2013年11月7日下午1:34:29 org.apache.fop.events.LoggingEventListener processEvent
    Warnung:Glyph? (0x95)在字体Times-Roman中不可用。
    2013年11月7日下午1:34:29 org.apache.fop.events.LoggingEventListener processEvent
    Warnung:未找到字体Arial,italic,400。用任意,斜体,400代替。
    2013年11月7日下午1:34:29 org.apache.fop.events.LoggingEventListener processEvent
    Warnung:内容溢出第1页的fo:region-before的块视图方向上的视口2989 millipoints。 (见位置50:-1)
    2013年11月7日下午1:34:29 org.apache.fop.events.LoggingEventListener processEvent
    信息:Rendered page#1。
    2013年11月7日下午1:34:29 org.apache.fop.events.LoggingEventListener processEvent
    Warnung:内容溢出第2页的fo:region-before的块视图方向上的视口2989 millipoints。 (见位置59:-1)
    2013年11月7日下午1:34:29 org.apache.fop.events.LoggingEventListener processEvent
    信息:渲染页面#2。

    不介意URL。

    解决方案

    我有同样的问题,使用.NET中的FopFactory,并解决了Apache文档中的java示例:



    我用这段代码创建了一个配置文件:

     <?xml version =1.0 encoding =utf-8?> 
    < fop>
    < renderers>
    < renderer mime =application / pdf>
    < fonts>
    < auto-detect />
    < / fonts>
    < /渲染器>
    < /渲染器>
    < / fop>

    然后添加信息FopFactory:

      FopFactory fopFactory = FopFactory.newInstance(); 
    fopFactory.setUserConfig(fop.xconf);

    自动检测选项用于检测系统中的所有字体,可能需要一段时间而且产量也很大。
    要从系统配置特定字体,请参阅上面链接中的文档。


    I am tring to get Apache FOP to use Arial as font. So far, without luck.

    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>
    

    But it doesnt seem to work. When I start FOP on the command line it says font Arial normal not found.

    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.

    Any suggestions?

    UDPDATE:

    I put them in the folder fop/src/codegen

    I also put the arial.tff there

    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>
    

    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...

    ++ UPDATE ++

    Okay...

    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>
    

    I've added font-family="Arial" to pretty much all the elements now :D

    I go to my fop directory in the command line and enter

    fop -xml blabla\file.xml -xsl blabla\stylesheet.xsl -pdf output.pdf
    

    And i get the following:

    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.
    

    Dont mind the URLs.

    解决方案

    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>
    

    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中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 13:28