How to use FastReport Core in Linux
In the previous article we have considered an example of using a new product of FastReport - the FastReport Core. That was an example for Windows. This time we will overview an example for Linux.
First of all, for Linux need additional libraries, which may not be installed by default:
Usually, the xserver is not installed on the server OS Linux. However, it is necessary for processing graphics of the FastReport Core. So, we have to install it. It can be, for example: Xvfb, VcXsrv etc.
We will revert to the issue of the xserver later, but for now, let us create the ASP.Net Core application:
Choose a Web application:
Add the FastReport Core to the project via NuGet.
We add a local repository as the source of the packages in the NuGet options:
Set a reference to the local repository or a folder Service FastReport.2017.4.0-release.nupkg:
Select the local source of packages in the drop - down list and install the FastReport package.
Open the "HomeController.cs" file from the "Controllers" folder. We add several additional libraries to the uses section:
Let us edit the Index method:
Since the WebReport object is not yet available to us in the FastReport Core, we use a usual Report object. Create a data source and register it in the Report object. Load the report template. Prepare the report, using the Prepare () method. Next, we create an export of the finished report in HTML. We export in the MemoryStream stream (or in a file). Then we pass the report to the view using ViewData or ViewBag.
Now go on to edit the "Views -> Index.chtml" view.
The procedure is simle - we just display the report in HTML format:
As it was said earlier, the FRCore requires the xserver, which is not presented in the server-side Linux.
Here is an example of adjusting Linux using the debian server:
1. Open the console;
2. Update apt-get and install the packages:
- sudo apt-get update;
- sudo apt-get install -y xvfb x11vnc x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps libgdiplus libx11-dev.
3. Change the environment variable. DISPLAY =: 99.
We add two methods in the Program class. The LinuxStart method checks if the xserver is being run. If so, it closes it down and creates a new one.
The StopLinux method simply stops the virtual server.
The application is ready. Run it:
Summing up, we can conclude, that the application for Linux turned out to be just as simple as the Windows application. However, it requires some advanced settings of the operating system to work with .Net Core.