Can I use Reporting with Azure functions

1 Answer 320 Views
.NET Core General Discussions
emad
Top achievements
Rank 1
emad asked on 26 Mar 2023, 03:26 AM

I have a web application that consists of an API hsoted in Azure functions and a front end as Blazor wasm hosted in Azure blob storage as statis site.

I need to add a report for users so that each user see their own data based on data passed to the report.

1) Can reporting be used with Azure functions?

2) If yes, any sample code to guide me?

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 28 Mar 2023, 11:07 AM

Hello Emad,

Azure Functions

We have had clients who have successfully hosted the Reporting REST Service on Azure functions, so it should be possible. However, there are a couple of factors that have to be taken into account.

For one, we rely on the GDI+ (System.Drawing) functionality for rendering our reports. This is a must. I am not sure what is the environment of the Azure Functions, i.e. Windows or Linux. For that reason, I will share what we are aware of regarding the two platforms.

Starting with .NET 6, Microsoft is about to deprecate System.Drawing for non-Windows platforms. The workaround may be found in the KB System.Drawing.Common is not supported on non-Windows platforms - .NET 6 under Linux. If you use Linux, please, check also the article section Deploying on Linux.

Also, as far as I am aware, some Azure plans don't allow System.Drawing for security reasons even on Windows. To validate whether you have System.Drawing, you may test to instantiate a new Bitmap outside Telerik Reporting functionality:

var bmp = new System.Drawing.Bitmap(10, 10);

If the above line of code throws, this means that System.Drawing is not deployed, hence Telerik Reporting cannot work in this environment.

Code Samples

There isn't any code specific to Azure, please feel free to follow the next articles for integrating the Reporting service and the blazor viewer:

There are also sample projects that you may use for your tests. They are shipped with the installation of the Telerik Reporting product and you may find them at the following path:

C:\Program Files (x86)\Progress\Telerik Reporting <Release>\Examples\CSharp

I hope this will help, please do not hesitate to let me know if you have any further questions.

Regards,
Dimitar
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
emad
Top achievements
Rank 1
commented on 01 Apr 2023, 03:10 PM

Thanks for the clarification.

I tested 

var bmp = new System.Drawing.Bitmap(10, 10);

In my azure functions environment and it is working fine (I am using windows host for my httptrigger azure functions).

I am just struggling to get it to work in httptriggered azure functions as the samples provided reference ReportsControllerBase.

Do you happen to have azure functions sample code?

 

 

 

Dimitar
Telerik team
commented on 05 Apr 2023, 12:44 PM

Would it not be possible to have a controller that inherits from the ReportsControllerBase class? If you are not able to implement the controller there, it will not be possible to use the web-based report viewer.

As a workaround, you may test to instead use the ReportProcessor class to export the report to PDF in code and to have it displayed in your application via the Blazor PdfViewer - Overview - Telerik UI for Blazor component.

For details on how reports can be rendered in code, please refer to the Generating Reports Programmatically - Telerik Reporting article.

Sagar
Top achievements
Rank 1
commented on 26 Feb 2024, 07:33 AM | edited

 

Can we add a Custom function for Telerik report in Azure function?

like i have custom function called "GetSchoolName"

and i want to use this custom function in one of cell in Telerik report as a value like "=Myfunction.GetSchoolName()"

 

Custom function with FunctionAttribute

[Function(Category = "Report Functions", Namespace = "Myfunction", Description = "Get Label Text")]

public static string GetSchoolName()

{ return "Hii school"; }

 

if we can add a custom function in azure function, then please code the snippet for that

Dimitar
Telerik team
commented on 28 Feb 2024, 01:16 PM

It should be possible to use custom functions in the Azure functions, you may visit the Custom User Functions Explained - Telerik Reporting article for details on how user functions are set up.

If you are rendering the reports using a Reporting REST Service, you visit Configuration for the Report Viewer/Web Report Designer for details on how to set up the assembly with the custom functions within that project.

If you are rendering the reports using the ReportsProcessor class, you need to reference the assembly with the custom functions in the project where that code is executed and you should also add an entry for it within your configuration using the assemblyReferencesElement - assemblyReferences Element Configuration - Telerik Reporting. Then, you may generate an IConfiguration instance of the configuration file(e.g. appsettings.json) and pass that to the ReportProcessor via its constructor:

            IConfiguration configuration = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json")
                .Build();


            var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor(configuration );

 

 

Sagar
Top achievements
Rank 1
commented on 15 Mar 2024, 08:51 AM

Thank you for the solution, it works perfectly.

Using the free Telerik service plan in the Azure function, we have made the following changes to download the Telerik file.

IConfiguration configuration = new ConfigurationBuilder()
   .SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("local.settings.json")
   .Build();

Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor(configuration);

RenderingResult result = reportProcessor.RenderReport(IsExcel?.ToLower() == "true" ? "XLSX" : "PDF", reportSource, null);

 

When we tried to download the Telerik report file (solution hosted on the Azure portal) from an Azure function, we encountered the following exception.


2024-03-14T14:13:57Z   [Information]   System.Exception:    at System.Drawing.Graphics.GetHdc()
   at Telerik.Reporting.Pdf.PdfContext..ctor(String ownerPassword, String userPassword)
   at Telerik.Reporting.Pdf.PdfDocument.InitCompleted(Stream stream)
   at Telerik.Reporting.ImageRendering.DocumentPdf.CreateDocument(PdfRenderingContext pdfContext)
   at Telerik.Reporting.ImageRendering.DocumentPdf.ResolveDocument()
   at Telerik.Reporting.ImageRendering.DocumentPdf..ctor(PdfRenderingContext context, IMeasureContext measureContext)
   at Telerik.Reporting.ImageRendering.PdfReport.CreateDocument(IDictionary renderingInfo, IDictionary deviceInfo, CreateStream createStreamCallback, PageSettings pageSettings)
   at Telerik.Reporting.ImageRendering.PdfReport.CreateWriter(IDictionary renderingContext, IDictionary deviceInfo, CreateStream createStreamCallback, PageSettings pageSettings)

Dimitar
Telerik team
commented on 19 Mar 2024, 02:52 PM

This exception indicates an issue with the GDI API, perhaps it is not fully supported in the Azure Function environment. In what OS is the code executed and which version of Reporting do you use?

I would recommend installing the latest version of the product - Telerik Reporting - Progress® Telerik® Reporting 2024 Q1 (18.0.24.305), and then switching to the Skia graphics engine. You may do so from the local.settings.json configuration file that you pass to the report processor:

{
"telerikReporting": {
   ...
  "processing": {
    // The element below sets the graphics engine used for processing and rendering.
    // The 'Skia' graphics engine requires reference to the package/assembly 'Telerik.Drawing.SkiaSharp' and its dependencies
     "graphicsEngine": {
      "engineName": "Skia" // available values: "Skia", "GDI", "PlatformDependent"
    },
  }
}

For more details on how to configure the graphics engine, you may refer to the Configuring the processing Element - Telerik Reporting article. Please note that to use the Skia engine, it is also necessary to install the Telerik.Drawing.Skia NuGet package to the project.

 

Tags
.NET Core General Discussions
Asked by
emad
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or