Articles in this section

How to pass embedded font for exporting in OnReportLoaded method

In our ReportViewer and ReportWriter does not have direct support for Exporting Unicode text to PDF. Unicode fonts cannot be embedded directly ReportViewer and ReportWriter application.

Add Unicode font stream to PDFFonts in code behind

Instead, the Unicode font files can be added as an embedded resource to the application. The Unicode font streams need to be added to the ReportViewer and ReportWriter PDFFonts collection to export report as PDF format with Unicode fonts as shown in the below code snippet.

ReportViewer

        public void OnReportLoaded(ReportViewerOptions reportOption) 
        { 
            if (reportOption.ReportModel.PDFOptions == null) 
            { 
                reportOption.ReportModel.PDFOptions = new PDFOptions(); 
            } 
            this.AddFonts(reportOption.ReportModel.PDFOptions); 
        } 
 
        private void AddFonts(PDFOptions pdfOpt) 
        { 
            this.AddFont(pdfOpt, "Arial"); 
        } 
 
        public void AddFont(PDFOptions pdfOpt, string name) 
        { 
            var path = HttpContext.Current.Request.PhysicalApplicationPath; 
            FileStream inputStream = new FileStream(path+@"\App_Data\Arial.ttf", FileMode.Open, FileAccess.Read); 
            if (pdfOpt.Fonts == null) 
            { 
                pdfOpt.Fonts = new Dictionary<string, Stream>(StringComparer.OrdinalIgnoreCase); 
            } 
            pdfOpt.Fonts.Add(name, inputStream); 
        } 
 

 

ReportWriter

            string NameSpc = Assembly.GetExecutingAssembly().GetName().Name.ToString(); 
            // First load the font as a memory stream 
            Stream stmFont = Assembly.GetExecutingAssembly().GetManifestResourceStream(NameSpc + ".arial.ttf"); 
            ReportWriter reportWriter = new ReportWriter(inputStream); 
            reportWriter.ReportProcessingMode = ProcessingMode.Remote; 
            reportWriter.PDFOptions = new Syncfusion.ReportWriter.PDFOptions(); 
            reportWriter.PDFOptions.Fonts = new Dictionary<string, Stream>(StringComparer.OrdinalIgnoreCase); 
            reportWriter.PDFOptions.Fonts.Add("Arial", stmFont); 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied