开发者

I can't change my Font Family using Apache FOP

开发者 https://www.devze.com 2023-04-04 19:24 出处:网络
I am trying to use fop Quick Start Guide to print a simple PDF file from a simple XML file and it works fine. but when I change <name>Frank</name> to <name>امیررضا</name>

I am trying to use fop Quick Start Guide to print a simple PDF file from a simple XML file and it works fine. but when I change <name>Frank</name> to <name>امیررضا</name> (change name to other encoding) I get #### in my printed PDF. I search through the Internet and couldn't find any feasible solution. I use many config files here are some of my them:

I use this command for creating pdf:

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

When I use this command I get below warning:

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 contains:

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

2-name2fo.xsl contains:

<?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开发者_StackOverflow中文版: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- have try many different config file (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: ......

The result output is:

Hello, #######!

Can anyone help me fix this?


Support for languages written with right-to-left scripts such as Arabic & Hebrew and full bidi support was added in Apache FOP 1.1. Based on the date of this question, an older Apache FOP version was used. For more information, see http://xmlgraphics.apache.org/fop/trunk/complexscripts.html.


I have never used Apache FOP but I found this article that allows you to create multiple language PDF.

  • Creating Multiple Language PDFs using Apache FOP


I would recommend that you use HelveticaWorld thatcontains arabic characters too or if you create the FOP input dynamically, then you can use Velocity or Freemarker variables to store the Font name.


I solve the problem by add font-family in XSL code:

name2fo.xsl after changes contains:

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

But I still have problem which is my Farsi character printed in reverse order. I mean if I want to print "Hello" it was printed "oellH" (you can imagine Hello is written in Farsi character) and also have a second problem that is the character was printed separated.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号