我无法使用Apache FOP更改我的字体系列

时间:2011-09-15 04:59:10

标签: java xsl-fo apache-fop

我使用fop Quick Start Guide从简单的XML文件打印一个简单的PDF文件,它工作正常。但是当我将<name>Frank</name>更改为<name>امیررضا</name>(将名称更改为其他编码)时,我的打印PDF中会显示####。我通过互联网搜索,没有找到任何可行的解决方案。我在这里使用了很多配置文件是我的一些配置文件:

我使用此命令创建pdf:

fop -c cfg.xml -xml name.xml -xsl name2fo.xsl -pdf name.pdf

当我使用此命令时,我收到以下警告:

WARNING: xHeight value could not be determined. The font may not work as
Sep 15, 2011 9:15:37 AM org.apache.fop.events.LoggingEventListener proce
WARNING: Glyph "╙" (0x633, afii57427) not available in font "Helvetica".
Sep 15, 2011 9:15:37 AM org.apache.fop.events.LoggingEventListener proce
WARNING: Glyph "╘" (0x634, afii57428) not available in font "Helvetica".

1- name.xml包含:

<name>امیررضا</name>

2-name2fo.xsl包含:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <fo:root>
      <fo:layout-master-set>
        <fo:simple-page-master master-name="A4-portrait"
              page-height="29.7cm" page-width="21.0cm" margin="2cm">
          <fo:region-body/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="A4-portrait">
        <fo:flow flow-name="xsl-region-body">
          <fo:block>
            Hello, <xsl:value-of select="name"/>!
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
</xsl:stylesheet>

3-尝试了许多不同的配置文件(cfg.xml)。

3.1:

<fop version="1.0">
<renderers>
    <renderer mime="application/pdf">      
      <fonts>
        <substitutions>
         <substitution>
            <from font-family="Helvetica" />
            <to font-family="SansSerif"/>
         </substitution>
        </substitutions>
        <referenced-fonts>
            <match font-family=".*"/>        
        </referenced-fonts>     
           <!-- register all the fonts found in a directory and all of its sub directories (use with care) -->
        <directory recursive="true">G:\....\fop\fop-1.0\Core14_AFMs</directory>

         <!-- automatically detect operating system installed fonts -->
        <auto-detect/>  
      <font embed-url="C:\WINDOWS\Fonts\times.ttf">
        <font-triplet name="Times New Roman" style="normal" weight="normal"/>
      </font>
      </fonts>
    </renderer>
  </renderers>
</fop>

3.2:

<fop version="1.0">
<renderers>
    <renderer mime="application/pdf">      
      <fonts>
        <substitutions>
         <substitution>
            <from font-family="Helvetica" />
            <to font-family="SansSerif"/>
         </substitution>
        </substitutions>
        <referenced-fonts>
            <match font-family=".*"/>        
        </referenced-fonts>               

         <!-- automatically detect operating system installed fonts -->
        <auto-detect/>  
      </fonts>
    </renderer>
  </renderers>
</fop>

3.3:......

结果输出为:

  

你好,#######!

任何人都可以帮我解决这个问题吗?

4 个答案:

答案 0 :(得分:2)

支持使用从右到左脚本编写的语言,例如阿拉伯语和阿拉伯语。 Apache FOP 1.1中添加了希伯来语和完全双向支持。根据此问题的日期,使用了较旧的Apache FOP版本。有关详细信息,请参阅http://xmlgraphics.apache.org/fop/trunk/complexscripts.html

答案 1 :(得分:0)

我从未使用过Apache FOP,但我发现这篇文章允许您创建多语言PDF。

答案 2 :(得分:0)

我建议您使用包含阿拉伯字符的HelveticaWorld,或者如果您动态创建FOP输入,则可以使用Velocity或Freemarker变量来存储字体名称。

答案 3 :(得分:0)

我通过在XSL代码中添加font-family解决了这个问题:

更改后的

name2fo.xsl包含:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <fo:root>
      <fo:layout-master-set>
        <fo:simple-page-master master-name="A4-portrait"
              page-height="29.7cm" page-width="21.0cm" margin="2cm">
          <fo:region-body/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="A4-portrait">
        <fo:flow flow-name="xsl-region-body">
          <fo:block font-size="10pt" font-family="Tahoma">
            Hello, <xsl:value-of select="name"/>!
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
</xsl:stylesheet>

但我仍有问题,那就是我的波斯语字符以相反的顺序打印。我的意思是,如果我想要打印“你好”它打印“oellH”(你可以想象你好用波斯语写的字符),还有第二个问题就是字符是分开打印的。

相关问题