0

I am very new to XSL-Fo.I am working on a scenario in which i have to include some chinese font while generating pdf.I have downloaded a TTF file with chinese font.But i am not able to apply it to text.I dont know how to apply the ttf file font into XSL.My code is below :

XSL_Code

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.1"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"
    exclude-result-prefixes="fo">
<xsl:attribute-set name="fontStyles">
    <xsl:attribute name="embed-url">URL('FourthTaskInput/GoJuOn.TTF') format('ttf')</xsl:attribute>
    <xsl:attribute name="background-color">#BB5588</xsl:attribute>
    <xsl:attribute name="border-bottom">solid 2pt #409C94</xsl:attribute>
    <xsl:attribute name="border-top">solid 2pt #409C94</xsl:attribute>
    <xsl:attribute name="font-size">9pt</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="student">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <fo:simple-page-master master-name="student-details">
      <fo:region-body margin="1in"/>
      <fo:region-before region-name="xsl-region-before" extent="5in"/>
      <fo:region-after region-name="xsl-region-after" extent=".5in"/>
    </fo:simple-page-master>
  </fo:layout-master-set>
  <fox:external-document content-type="pdf" src="FourthTaskInput//CoverPage.pdf"/> 
  <fo:page-sequence master-reference="student-details">
       <fo:static-content flow-name="xsl-region-before">
            <fo:block text-align="center"  margin-top="10mm"  margin-bottom="10mm">Header</fo:block>
        </fo:static-content>
        <fo:static-content flow-name="xsl-region-after">
            <fo:block text-align="center">Page No <fo:page-number/></fo:block>
        </fo:static-content>
    <fo:flow flow-name="xsl-region-body">
      <fo:block>
       <xsl:for-each select=".">
            <fo:table break-after="page" xsl:use-attribute-sets="fontStyles">
                <fo:table-body>
                <fo:table-row>
                    <fo:table-cell border="solid black"text-align="center" font-weight="bold" width="1cm">
                        <fo:block >
                            Id.
                        </fo:block>
                    </fo:table-cell>
                    <fo:table-cell border="solid black"text-align="center" font-weight="bold" width="3cm">
                        <fo:block font-family="Tahoma">
                            Name
                        </fo:block>
                    </fo:table-cell>
                    <fo:table-cell border="solid black" text-align="center" font-weight="bold" width="1.5cm" >
                        <fo:block>
                            Grade
                        </fo:block>
                    </fo:table-cell>
                        <fo:table-cell border="solid black" text-align="center" font-weight="bold"  width="2.5cm">
                        <fo:block>
                            DOB
                        </fo:block>
                    </fo:table-cell>
                </fo:table-row>
             </fo:table-body>
        </fo:table>
        </xsl:for-each>
      </fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>

I am not sure whether the part where i have mentioned the URL('FourthTaskInput/GoJuOn.TTF') format('ttf') is the right way to import the ttf file into the XLS-FO.Even if so i am not sure how to use it to make the fonts print as the chinese font in pdf.Can anyone help me out with this.

R. Richards
  • 21,615
  • 9
  • 55
  • 58
  • If you are using FOP, you have to [properly configure the font](http://stackoverflow.com/a/28251945/4453460). – lfurini Apr 29 '17 at 06:44

1 Answers1

0

FWIW, I have never seen an @embed-url attribute before.

Since you seem to be using FOP, see https://xmlgraphics.apache.org/fop/2.2/fonts.html#custom for the FOP documentation on using custom fonts.

Tony Graham
  • 5,853
  • 9
  • 18