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:
// Method will be called to initialize the report information to load the report with ReportHelper for processing.public void OnInitReportOptions(ReportViewerOptions reportOption){string basePath = _hostingEnvironment.WebRootPath;// 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.FileStream reportStream = new FileStream(basePath + @"\reports\"+ reportOption.ReportModel.ReportPath, FileMode.Open, FileAccess.Read);reportOption.ReportModel.Stream = reportStream;IListcustomers = new List () { new Customer() { Name = "Name1", Age = 25},new Customer() { Name = "Name2", Age = 22},new Customer() { Name = "Name3", Age = 23},new Customer() { Name = "Name4", Age = 26}};reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "DSTCustomers", Value = customers });string resourceName = "ReportTests.Resources.Arial.ttf";if (reportOption.ReportModel.PDFOptions == null){reportOption.ReportModel.PDFOptions = new Syncfusion.Reporting.Writer.PDFOptions();}if (reportOption.ReportModel.PDFOptions.Fonts == null){reportOption.ReportModel.PDFOptions.Fonts =new Dictionary(StringComparer.OrdinalIgnoreCase); }reportOption.ReportModel.PDFOptions.Fonts.Add("Arial",Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName));}
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.