We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Add custom font - Problem when exporting to PDF

Thread ID:





146453 Aug 5,2019 01:39 AM UTC Aug 6,2019 02:34 PM UTC Report Platform 5
Tags: General
Asked On August 5, 2019 01:46 AM UTC

Hi, I've been using the report tools for .net core and currently I'm trying to add a custom font (Arial) when the user export my reports as PDF. I'm using the following code in the reporting API for accomplishing this:

  1. // Method will be called to initialize the report information to load the report with ReportHelper for processing.
  2. public void OnInitReportOptions(ReportViewerOptions reportOption)
  3. {
  4. string basePath = _hostingEnvironment.WebRootPath;

  5. // Here, we have loaded the sales-order-detail.rdl report from application the folder wwwroot\Resources. sales-order-detail.rdl should be there in wwwroot\Resources application folder.
  6. FileStream reportStream = new FileStream(basePath + @"\reports\"
  7. + reportOption.ReportModel.ReportPath, FileMode.Open, FileAccess.Read);

  8. reportOption.ReportModel.Stream = reportStream;

  9. IList customers = new List() { 
  10. new Customer() { Name = "Name1", Age = 25},
  11. new Customer() { Name = "Name2", Age = 22},
  12. new Customer() { Name = "Name3", Age = 23}, 
  13. new Customer() { Name = "Name4", Age = 26}
  14. };

  15. reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "DSTCustomers", Value = customers });

  16. string resourceName = "ReportTests.Resources.Arial.ttf";

  17. if (reportOption.ReportModel.PDFOptions == null)
  18. {
  19. reportOption.ReportModel.PDFOptions = new Syncfusion.Reporting.Writer.PDFOptions();
  20. }

  21. if (reportOption.ReportModel.PDFOptions.Fonts == null)
  22. {
  23. reportOption.ReportModel.PDFOptions.Fonts =

  24. new Dictionary(StringComparer.OrdinalIgnoreCase);
  25. }

  26. reportOption.ReportModel.PDFOptions.Fonts.Add("Arial",
  27. Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName));
  28. }

This code works but when the user exports the report multiple times this happens eventually:

For tests, I wrapped the resource stream in a class that doesn't close the stream under any situation (something like "NonClosingStreamWrapper"). This way the problem doesn't seem to happen.

How can I fix this?

Regards, Wendell.

Vinoth Srinivasan [Syncfusion]
Replied On August 5, 2019 12:26 PM UTC

Hi Wendell, 
Thanks for your interest in Syncfusion products. 
We have validated the reported problem at our end, but the custom font has been working fine. So, it is possible for you to share your report and font file (ttf file) with us and it will be helpful for us to provide the solution at the earliest. 
Vinoth S. 

Replied On August 5, 2019 06:01 PM UTC

Hi, I have attached the project with the report + font.

Regards, Wendell.

Attachment: ReportTests_d91315d.zip

Vinoth Srinivasan [Syncfusion]
Replied On August 6, 2019 12:28 PM UTC

Hi Wendell, 

We were able to reproduce this issue and logged a defect report on this. It will be included in our upcoming releases. You can track this issue from the below feedback portal system. 

Vinoth S. 

Replied On August 6, 2019 02:22 PM UTC

Ok, thank you.

Regards, Wendell.

Vinoth Srinivasan [Syncfusion]
Replied On August 6, 2019 02:34 PM UTC

Hi Wendell, 

Thanks for your update. Please let us know if you require further assistance on this. 

Vinoth S. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon