Render local pdf reports in c# from .rdlc template for cross platform as using System.Drawing is not supported for non-windows platforms

53 views Asked by At

I am trying to render PDF reports in my C# API, but I got an exception for non-Windows platform as System.Drawing is not supported on .NET 7.0.

This code is working fine under Windows, but not on non-Windows.

var dt = new DataTable();
var path = Path.Join(this._webHostEnvironment.WebRootPath, "Reports", "TestReport.rdlc");
LocalReport report = new LocalReport();
dt = _context.PrepareStoredProcedure("sp_GetReportDetails")
     .ExecuteDataTable();

report.DataSources.Add(new ReportDataSource("Report_Data", dt));
report.ReportPath = path;
report.SubreportProcessing += new SubreportProcessingEventHandler(SubreportProcessingNew);
var pdf = report.Render(renderFormat);
return pdf;

SubreportProcessingNew body as follows:

private void SubreportProcessingNew(object sender, SubreportProcessingEventArgs e)
{
     if (e.ReportPath == "Report_Data")
     {
         var dt2 = new DataTable();
         dt2 = _context.PrepareStoredProcedure("Sp_Get_Report_Data")
             .ExecuteDataTable();
         ReportDataSource ds = new ReportDataSource("Report_Data", dt2);
         e.DataSources.Add(ds);
     }
}

On docker container I got exception:

[ERR] The type initializer for 'Microsoft.ReportingServices.Rendering.ImageRenderer.Renderer' threw an exception. (e02b7569)
Microsoft.Reporting.NETCore.LocalProcessingException: An error occurred during local report processing.
 ---> System.TypeInitializationException: The type initializer for 'Microsoft.ReportingServices.Rendering.ImageRenderer.Renderer' threw an exception.
 ---> System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.
   at System.Drawing.Image..ctor()
   at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
   at Microsoft.ReportingServices.Rendering.ImageRenderer.Renderer..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.ReportingServices.Rendering.ImageRenderer.Renderer..ctor(Boolean physicalPagination)
   at Microsoft.ReportingServices.Rendering.ImageRenderer.PDFRenderer.Render(Report report, NameValueCollection deviceInfo, Hashtable renderProperties, CreateAndRegisterStream createAndRegisterStream)
   at Microsoft.ReportingServices.Rendering.ImageRenderer.RendererBase.Render(Report report, NameValueCollection reportServerParameters, NameValueCollection deviceInfo, NameValueCollection clientCapabilities, Hashtable& renderProperties, CreateAndRegisterStream createAndRegisterStream)
   --- End of inner exception stack trace ---

Is there any other free available library which can be used to render PDF report from .rdlc template?

0

There are 0 answers