Fonts 在apachefop中嵌入字体

Fonts 在apachefop中嵌入字体,fonts,apache-fop,Fonts,Apache Fop,我试图让ApacheFop使用Arial作为字体。到目前为止,没有运气 在my config.xml中,它表示: <fonts> <font kerning="yes" embed-url="file:///C:/Windows/Fonts/Arial.ttf" encoding-mode="auto">> <font-triplet name="Arial" style="normal" weight

我试图让ApacheFop使用Arial作为字体。到目前为止,没有运气

在my 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>
也许我看不到森林,但我不知道该怎么办

有什么建议吗

更新日期:

  • 我从这个网站下载了很多xml文件: (在我看来,这与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>
我得到以下信息:

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.

不要介意URL。

类NotFoundException表示您有类加载问题。鉴于它缺少
org.apache.xmlgraphics.fonts.Glyphs
,这意味着您的类路径中没有
xmlgraphics commons.jar
(或过时的版本)。您可以在FOP的
lib
目录中找到这个问题。

我也遇到了同样的问题,使用.NET中的FopFactory并用Apache文档上的java示例解决了这个问题:

我使用以下代码创建了一个配置文件:

<?xml version="1.0" encoding="utf-8" ?>
 <fop>
   <renderers>
    <renderer mime="application/pdf">
     <fonts>
       <auto-detect/>
     </fonts>
    </renderer>
  </renderers>
 </fop>
“自动检测”选项用于检测系统上的所有字体,可能需要一段时间,并且输出的字体尺寸较大。
要从系统中配置特定字体,请参阅上面链接中的文档。

我只是想在这里为仍对此感到疑惑的人添加一个部分解决方案,要生成xml文件,还需要将xmlgraph_commons-1.4.jar添加到类路径

此外,应用程序的路径是org.apache.fop.fonts.apps.TTFReader,而不是OP发布的路径,至少在旧版本的fop中是这样

这是一个有效的出口

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;lib\xmlgraphics-
commons-1.4.jar org.apache.fop.fonts.apps.TTFReader C:\Windows\Fonts\arial.ttf A
rial.xml

出于历史原因,Helvetica是postscript的默认字体,FOP PDF渲染基于该字体。因此,如果您没有在XSL模板中显式声明字体,FOP将尝试使用Helvetica

所以我的问题是FOP在生成PDF/a文档时试图嵌入Helvetica字体,但Helvetica从未在模板中声明,也没有安装在我的Linux系统上

解决方案很简单,我在fopconf.xml中映射了Helvetica的替换,并以这种方式将LiberationSans设置为默认字体。示例fopconf.xml:

<fop version="1.0">
    <renderers>
        <renderer mime="application/pdf">
        <fonts>
            <!-- auto-detect operating system installed fonts -->
            <auto-detect />

            <!-- substitute default unfree font Helvetica with free font LiberationSans 
                (which is an Arial Clone, which is an Helvetica Clone) -->
            <substitutions>
                <substitution>
                    <from font-family="Helvetica" />
                    <to font-family="LiberationSans" />
                </substitution>
            </substitutions>
        </fonts>
        </renderer>
    </renderers>
</fop>

对于使用其他字体的模板,另一种解决方案是直接在根元素上设置字体族,如

希望我的回答能给这个问题增加一些附加值


[UPDATE]我可以补充一点,我使用的是FOP2.1[/UPDATE]

我遇到了完全相同的问题(尽管Windows上有s/Arial/Verdana/和fwiw-FOP-2.1)。在尝试了各种各样的事情之后,我退了一步,发现我犯的错误和我们许多人犯的一样-

  • 我正在编辑提供的/示例配置文件,该文件具有非默认扩展名,因此fop(即fop.xconf)不会自动使用
  • fop.bat(或任何其他提供的平台调用脚本)不使用-c fop.xconf调用org.apache.fop.cli.Main,也不使用任何.conf文件调用-c,因此不使用对fop.xconf的任何更改
  • 对我有效的解决方案是-

  • 创建
    conf\fop.conf
  • 确保为fop提供conf文件,即使用-c选项调用fop.bat(或其他平台脚本),例如-

  • fop.bat-fo path\to\fo.fo-c path\to\fop.conf-pdf path\to\output.pdf

    正如我之前所说,我们并不是唯一一个被这件事抓住的人-


    IMHO-我想如果ApacheFop分发时带有一个空的FOP.conf,调用脚本中已经引用了它,我们就不会被这个问题所困扰了。

    ,将其添加到我的路径变量:C:\Users\z003a5bp\Desktop\FOP2\lib\commons-logging-1.1.3.jar我在控制台中键入以下内容:C:\Users\z003a5bp\Desktop\FOP2>java-cp build\fop.jar;lib\avalon-framework-4.2.0.jar;lib\commons-logging-1.1.3.jar;lib\commons-io-1.3.1.jar org.apache.fop.TTFReader C:\Users\z003a5bp\Desktop\FOP2\arial.ttf arial.xml所有这些jar都在这里可以看到的版本中的相应文件夹中,但现在我得到一条消息,主类TTFReader找不到或无法加载。我应该在前面看到:FOP1.0不再需要TTFReader或者以后。FOP可以动态地正确提取正确的字体度量。此外,考虑使用标签,而不是更容易地配置字体的FOP。我刚刚看到你更新了这个问题。如果使用,则会使C:\Windows\Fonts变得多余。要确保您确实不使用任何时间/serif字体,请在fo:root上指定font-family=“Arial”。最后,确保标记是正确格式特定标记的子标记。我再次更新了问题,以防您想再次查看。好的,将“-c fop.xconf”添加到命令行。从字体配置中删除度量url。实际上,您可以删除整个标记并使用..xconf-与“示例”无关,它更可能代表XML配置。只要我们将此文件作为配置提供,名称和扩展名就无关紧要。例如,在我正在检查的代码中,这个文件名为fop.xconf.xml
    <?xml version="1.0" encoding="utf-8" ?>
     <fop>
       <renderers>
        <renderer mime="application/pdf">
         <fonts>
           <auto-detect/>
         </fonts>
        </renderer>
      </renderers>
     </fop>
    
    FopFactory fopFactory = FopFactory.newInstance();
    fopFactory.setUserConfig("fop.xconf");
    
    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;lib\xmlgraphics-
    commons-1.4.jar org.apache.fop.fonts.apps.TTFReader C:\Windows\Fonts\arial.ttf A
    rial.xml
    
    <fop version="1.0">
        <renderers>
            <renderer mime="application/pdf">
            <fonts>
                <!-- auto-detect operating system installed fonts -->
                <auto-detect />
    
                <!-- substitute default unfree font Helvetica with free font LiberationSans 
                    (which is an Arial Clone, which is an Helvetica Clone) -->
                <substitutions>
                    <substitution>
                        <from font-family="Helvetica" />
                        <to font-family="LiberationSans" />
                    </substitution>
                </substitutions>
            </fonts>
            </renderer>
        </renderers>
    </fop>