PDF embed Traditional Chinese char question

2 posts, 0 answers
  1. Chris
    Chris avatar
    58 posts
    Member since:
    Oct 2015

    Posted 01 Mar 2016 Link to this post


    I use the RadPdfProcessing API to generate Pdf document and preview the pdf file in WinForm App.
    The pdf previewed by Acrobat Reader then the chinese char displayed normally, 
    but not works for Telerik.WinControls.UI.RadPdfViewer in WinForm
    (same as http://www.telerik.com/clientsfiles/445045_Wrong.jpg?sfvrsn=0)

    Generate pdf file c:\Hello1.pdf :

    // Reference :
    // FontsRepository.RegisterFont data Parameter
    Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.RegisterFont(new FontFamily("標楷體"),
    Telerik.Windows.Documents.Fixed.Model.Fonts.FontBase NewCreateFont;
       new FontFamily("標楷體"),
       out NewCreateFont);
      // Reference :
      Telerik.Windows.Documents.Fixed.Model.RadFixedDocument document2 = new Telerik.Windows.Documents.Fixed.Model.RadFixedDocument();
      Telerik.Windows.Documents.Fixed.Model.RadFixedPage page2 = document2.Pages.AddPage();
      Telerik.Windows.Documents.Fixed.Model.Editing.FixedContentEditor editor = new Telerik.Windows.Documents.Fixed.Model.Editing.FixedContentEditor(page2);
      editor.Position.Translate(50, 50);
      Telerik.Windows.Documents.Fixed.Model.Editing.Block block = new Telerik.Windows.Documents.Fixed.Model.Editing.Block();
      block.GraphicProperties.FillColor = Telerik.Windows.Documents.Fixed.Model.ColorSpaces.RgbColors.Black;
      block.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Left;
      block.TextProperties.Font = Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.HelveticaBoldOblique;
      block.TextProperties.FontSize = 40;
      block.TextProperties.Font = NewCreateFont; // Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.Helvetica;
      block.TextProperties.FontSize = 12;
      block.InsertText(" 中文字 is a document processing library that enables your application to " +
                       "import and export files to and from PDF format. The document model is " +
                       "entirely independent from UI and allows you to generate sleek documents " +
                       "with differently formatted text, images, shapes and more.");
      editor.DrawBlock(block, new System.Windows.Size(500, double.PositiveInfinity));
      Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider provider2 = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
      using (Stream output2 = File.OpenWrite("c:\\Hello1.pdf"))
        provider2.Export(document2, output2);



    Preview the pdf file c:\Hello1.pdf :

    private void button1_Click(object sender, EventArgs e)

    I have reference the forums and posts then embed the fonts into pdf file but the code still not works :

    Chinese characters support ?

    How can I generate and preview pdf file  normally in WinForm App? 

    Tools :

    Telerik DevCraft Q1 2016 SP1
    Windows 7
    Visual Studio 2015 Ultimate and .NET Framework 4.0

    Best regards



  2. Deyan
    Deyan avatar
    158 posts

    Posted 03 Mar 2016 Link to this post

    Hello Chris,

    There seems to be an issue with drawing the chinese glyph outlines in this specific font. I have found a similar FAQ in FontForge where it is described that the possible cause of the issue is incomplete glyphs geometry description in the font file that needs special threatment in order to render the glyphs correctly. We have logged this issue in our feedback portal. You can follow its implementation progress by following this feedback item.

    As a workaround you may try using different font such as "KaiTi" or "MS Mincho". If you are using a Winforms application to generate the file and some of these fonts is installed on your machine you won't even need to register the font. You may simply call TrySetFont method and RadPdfProcessing will find the installed font with the corresponding font properties. The following code snippet shows how to achieve this:
    block.TextProperties.TrySetFont(new System.Windows.Media.FontFamily("KaiTi"));

    I am attaching 3 PDF files generated using different approaches so that you can easily compare the results:
    • test-kaiu-ttf-chinese.pdf is generated by registering kaiu.ttf font. As mentioned the chinese glyphs are rendered wrong with this font.
    • test-simkai-ttf-chinese.pdf is generated by registering simkai.ttf font. This is the font file correspoding to "KaiTi" font family and this approach embeds the whole font data in the PDF file, which results in bigger file size. This file is correctly displayed in RadPdfViewer.
    • test-KaiTi-font family-chinese.pdf is generated by using the above code snippet for calling TrySetFont method with the corresponding font family. This time only a subset of "KaiTi" font is embedded which results in much smaller file size. This PDF is also displayed correctly in RadPdfViewer.

    I hope this information is helpful. If you have any other questions or concerns please do not hesitate to contact us again.

    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top