Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

c# - xslt fo does not show chinese or thai fonts

I am Convert a XSLT to PDF with Chinese characters in it. I am using Fonet.dll and csharp . I have added Chinese language's i.e. ZH and ZHT in the regional languages under control panel.

I am following the code example to generate the pdf

The XSLT is as follows

<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"  >
  <xsl:template match="/" >

    <fo:root xml:lang="en"
        xmlns:fo="http://www.w3.org/1999/XSL/Format" >
      <fo:layout-master-set>
        <fo:simple-page-master page-height="350mm"
                               page-width="271mm"
                               master-name="PageMaster">
          <fo:region-body />
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="PageMaster">
        <fo:flow flow-name="xsl-region-body" >

          <fo:block  font-family="MingLiU">
             hello-  您好
          </fo:block>
          <fo:block font-family="MS Mincho"
            >カニ入りスープなしの麺をください。</fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root> 
  </xsl:template>
</xsl:stylesheet>

The Chinese characters do not appear at all I all set the encoding to encoding="gb2312" but it did not make any difference.

Is there are a way I can embed the fonts in the XSLT so that the Chinese characters appear.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is probably a matter of font configuration, not of character encoding.

Provided that the fonts you want to use are effectively supported (the website states that FO.NET "supports TrueType and TrueType flavoured OpenType fonts"), you have to tell the formatter where they are (if the formatter does not automatically looks for them in the default system font folders) and how to use them: either reference them, embed the whole font in the PDF, or embed just the needed subset.

I have no direct experience using FO.NET, but according to this documentation page about fonts you need something like this in your code (you probably want to embed / subset the Chinese fonts):

FonetDriver driver = FonetDriver.Make();
driver.Renderer = RendererEngine.PDF;

// Font embedding/linking is set via PdfRendererOptions class
PdfRendererOptions options = new PdfRendererOptions();

// Use FontType enumeration to specify either Link, Embed or Subset
//options.FontType = FontType.Link;
options.FontType = FontType.Embed;
//options.FontType = FontType.Subset;

driver.Options = options;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...