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

Add custom font - Problem when exporting to PDF

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.


5 Replies

VS Vinoth Srinivasan Syncfusion Team August 5, 2019 07:26 AM

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. 
 
Regards, 
Vinoth S. 



WE Wendell August 5, 2019 01:01 PM

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


Regards, Wendell.

Attachment: ReportTests_d91315d.zip


VS Vinoth Srinivasan Syncfusion Team August 6, 2019 07:28 AM

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. 


Regards, 
Vinoth S. 



WE Wendell August 6, 2019 09:22 AM

Ok, thank you.


Regards, Wendell.


VS Vinoth Srinivasan Syncfusion Team August 6, 2019 09:34 AM

Hi Wendell, 

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

Regards, 
Vinoth S. 


Loader.
Live Chat Icon For mobile
Up arrow icon