How to add custom fonts to pdf reports as Chinese characters are not loading

Posted by: aswin.f on 23 May 2022, 3:26 pm EST

    • Post Options:
    • Link

    Posted 23 May 2022, 3:26 pm EST

    I am on ARv15. We support simplified and traditional Chinese in our web app and so we need to be able to support the same when we export pdf. However with the below code, of all the languages, for Chinese the text was coming blank

    this.StyleSheet.Add(new DDCssLib.StyleSheetRule("font-family: Arial Unicode MS; font-style: normal; text-decoration: none; font-we" +
                                                                "ight: normal; font-size: 10pt; color: Black", "Normal"));
                this.StyleSheet.Add(new DDCssLib.StyleSheetRule("font-size: 16pt; font-weight: bold", "Heading1", "Normal"));
                this.StyleSheet.Add(new DDCssLib.StyleSheetRule("font-family: Times New Roman; font-size: 14pt; font-weight: bold; font-style: ita" +
                "lic", "Heading2", "Normal"));
                this.StyleSheet.Add(new DDCssLib.StyleSheetRule("font-size: 13pt; font-weight: bold", "Heading3", "Normal"));
                this.ReportStart += new System.EventHandler(this.InspectionReport_ReportStart);
    

    This was happening in local dev environment where the characters were loading fine in all other app. I was able to get it working in local by adding the below code. I am not sure how this gets it working but that’s the only difference I could see from one of your sample code

    this.CompatibilityMode = GrapeCity.ActiveReports.Document.CompatibilityModes.CrossPlatform;
    

    Sadly this doesn’t work in QA and Prod. They are in docker and I am not sure if fonts are missing because of that and hence not able to load the characters as in a normal machine that has fonts from MS Office. Can you please tell me a way to get this working? Is there a way I can get AR to load fonts from the deployment folder? I have google’s Noto font available in project

  • Posted 23 May 2022, 3:27 pm EST - Updated 30 September 2022, 4:25 pm EST

    Attached screenshot of how Chinese characters load up in CICD environments

  • Posted 26 May 2022, 12:57 am EST

    Hello,

    When exporting in a medium trust environment, ActiveReports does not have access to the System Fonts folder due to security restrictions. Thus, you can use a custom font factory which would allow you to embed any fonts you need in exported PDF.

    Please take a look at the following links to the documentation on configuring custom fonts:

    https://www.grapecity.com/activereportsnet/docs/v15/online/pdf-custom-font-factory.html

    For more information on the config file, refer to the Custom Fonts section in the below link: https://www.grapecity.com/activereportsnet/docs/latest/online/activereports-configuration-file.html

    https://www.grapecity.com/activereportsnet/docs/v15/online/custom-font-resolver.html

    Regards

    Dushyant Sharma

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels