[Silverlight] Still not support chinese?

9 posts, 0 answers
  1. Vincent
    Vincent avatar
    9 posts
    Member since:
    Dec 2013

    Posted 04 Jul 2014 Link to this post

    I am very exciting for this new function, but it is seem not support chinese as well. I convert a xlsx file that contain chinese to the pdf. the chinese word disappeared.....
  2. Deyan
    Admin
    Deyan avatar
    137 posts

    Posted 08 Jul 2014 Link to this post

    Hello Vincent,

    Thank you for contacting us.

    When you want to export custom font to PDF you should first register the font using the FontsRepository. 
    The following example shows how to register "MS Mincho" font family using a font file "msmincho.ttc" (the file should be added to your project and should have build action "Resource" in its properties).
    public const string CustomFontResource = "Resources/msmincho.ttc";
    public static readonly FontFamily CustomFontFamily = new FontFamily("MS Mincho");
     
    private static void RegisterFont()
    {
        byte[] fontData = ResourceHelper.GetResourceData(CustomFontResource);
        FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Normal, FontWeights.Normal, fontData);
    }

    You should have in mind that using the FontsRepository requires you to add reference to Telerik.Windows.Documents.Fixed.dll. For more informations about fonts in PDF export you may follow this link to Fonts in PdfProcessing documentation article.

    When you have registered the font you can further set the font family in worksheet's cells when generating the document. The following code snippet shows how to set the previously registered font family to cell A1:
    worksheet.Cells[0, 0].SetFontFamily(new ThemableFontFamily(CustomFontFamily));

    Following this steps you could export the PDF with the desired font.

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

    Regards,
    Deyan
    the Telerik team
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. Vincent
    Vincent avatar
    9 posts
    Member since:
    Dec 2013

    Posted 31 Jul 2014 in reply to Deyan Link to this post

    thank you for your reply. If I register a font and packed in my project. Need I download the font file when I visit the web site.

    If I want to use the Chinese font that all the client pc have that, for example "Simsun" or "SimHei". Need I add the font file to the resource.


  4. Deyan
    Admin
    Deyan avatar
    137 posts

    Posted 04 Aug 2014 Link to this post

    Hello Vincent,

    Thank you for contacting us.

    To answer your questions:
    1. When you have registered some font in your silverlight project everyone who visits your web site will be able to see the content properly (there is no need to download this font locally on the client pc).
    2. Even if your client pc has some of the mentioned fonts locally, you will still have to register that font in your silverlight project (otherwise there will be issues with exporting PDF documents with this font).

    I hope this is helpful. If you have additional questions do not hesitate to contact us again.

    Regards,
    Deyan
    the Telerik team
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  5. Victor
    Victor avatar
    7 posts
    Member since:
    Jul 2014

    Posted 03 Dec 2014 in reply to Deyan Link to this post

    Hello Deyan,
    I can not find GetResourceData method in the class ResourceHelper(Telerik.Windows.Controls.Charting),why?
    byte[] fontData = ResourceHelper.GetResourceData(CustomFontResource);
  6. Deyan
    Admin
    Deyan avatar
    137 posts

    Posted 03 Dec 2014 Link to this post

    Hello Victor,

    The ResourceHelper class mentioned in previous code snippets should be implemented so that it can return the byte array of a resource file. Here follows a sample implementation of such class:
    public static class ResourceHelper
    {
        public static Uri GetResourceUri(string resource)
        {
            AssemblyName assemblyName = new AssemblyName(typeof(ResourceHelper).Assembly.FullName);
            string resourcePath = "/" + assemblyName.Name + ";component/" + resource;
            Uri resourceUri = new Uri(resourcePath, UriKind.Relative);
     
            return resourceUri;
        }
     
        public static Stream GetResourceStream(string resource)
        {
            return Application.GetResourceStream(ResourceHelper.GetResourceUri(resource)).Stream;
        }
     
        public static byte[] GetResourceData(string resource)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                ResourceHelper.GetResourceStream(resource).CopyTo(memoryStream);
                return memoryStream.ToArray();
            }
        }
    }

    In order to use ResourceHelper.GetResourceData() method you should first add the resource file in your project and set its build action as a "Resource".

    I hope this is helpful.

    Regards,
    Deyan
    the Telerik team
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Fredrik
    Fredrik avatar
    58 posts
    Member since:
    Mar 2013

    Posted 22 Feb in reply to Deyan Link to this post

    Hei, i have problems displaying the font Gill Sans MT on the pdf export, it reverts to a default font.

    It displays correctly in the radrichtextbox editor.

    I have implented the following

               FontFamily CustomFontFamily = new FontFamily("Gill Sans MT");
               FontManager.RegisterFont(CustomFontFamily);

     

                byte[] fontData = null;
                FontFamily CustomFontFamily = new FontFamily("Gill Sans MT");
                fontData = cResourceHelper.ResourceHelper.GetResourceData("Resources/Fonts/GIL_____.ttf");
                FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Normal, FontWeights.Normal, fontData);

                fontData = cResourceHelper.ResourceHelper.GetResourceData("Resources/Fonts/GILB____.ttf");
                FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Normal, FontWeights.Bold, fontData);

                fontData = cResourceHelper.ResourceHelper.GetResourceData("Resources/Fonts/GILBI___.ttf");
                FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Italic, FontWeights.Bold, fontData);

                fontData = cResourceHelper.ResourceHelper.GetResourceData("Resources/Fonts/GILC____.ttf");
                FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Normal, FontWeights.Normal, fontData);

                fontData = cResourceHelper.ResourceHelper.GetResourceData("Resources/Fonts/GILI____.ttf");
                FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Normal, FontWeights.Bold, fontData);

                fontData = cResourceHelper.ResourceHelper.GetResourceData("Resources/Fonts/GLSNECB.ttf");
                FontsRepository.RegisterFont(CustomFontFamily, FontStyles.Italic, FontWeights.Normal, fontData);

    The fonts are extracted from the windows font folder under "Gill Sans MT"

    and added to the project folder Resources/Fonts and build action as resource

  8. Deyan
    Admin
    Deyan avatar
    137 posts

    Posted 23 Feb Link to this post

    Hello Fredrik,

    Thank you for contacting us. 

    The FontsRepository class is used in PdfProcessing export to PDF. As RadSpreadProcessing and RadWordsProcessing libraries use PdfProcessing for their PDF export you may use FontsRepository class for registering fonts data when exporting PDFs with these two libraries as well.

    However, RadRichTextBox control uses a completely different code for its PDF export and it does not provide functionality for embedding fonts. We have logged such feature request in our feedback portal. You can vote for it and follow its implementation progress by following this feedback item.

    As a workaround for now you may use RadWordsProcessing for WPF to get PDF with "Gill Sans MT" font family in your Silverlight application through a web service. I am attaching a demo solution showing how exactly you can achieve that. A few words about the attached solution:
    • It contains a Silverlight project called WordsProcessingRegisterFontsFromServiceDemo. This project has a single button that exports a PDF file containing the desired font family. The PDF file is received by a web service. This may be seen in ServiceClientGetPdfWithGillSansMTCompleted method.
    • The second project is a web application called WordsProcessingRegisterFontsFromServiceDemo.Web. This project implements the web service that uses RadWordsProcessing for WPF to generate flow document containing "Gill Sans MT" font family and then exports it to PDF. This may be seen in WordsProcessingPdfService.svc.cs.
    • The current implementation does not register the "Gill Sans MT" font family as the web application has access to the system fonts. However, if you are not sure that this font will be installed on the machine that runs the service you may still register the font using the FontsRepository as mentioned in your post.
    • When you click on the button in the Silverlight application it simply exports the PDF file bytes previously received by the web service.

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

    Regards,
    Deyan
    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
  9. Fredrik
    Fredrik avatar
    58 posts
    Member since:
    Mar 2013

    Posted 24 Feb in reply to Deyan Link to this post

    Thanks for your answer.

    have resolved it with a serverside service, however hope you can put priority on fixing this on the client side also

Back to Top