Creating PDF report in JetBrains Rider (C#) on Ubuntu 22.04.1 LTS

2023-03-22

Creating PDF report in JetBrains Rider (C#) on Ubuntu 22.04.1 LTS

In this article, we'll take a look at the world of the .NET platform on Ubuntu 22.04.1 LTS without using Microsoft Visual Studio, as it can't be installed on Linux, and create a PDF exportable report. The current analog of Visual Studio is, of course, JetBrains Rider. It is a cross-platform .NET IDE developed by JetBrains. It supports C#, VB.NET, and F# programming languages.
We will not discuss which IDE is better or worse. Let's just create, build, and export a PDF report/document from JetBrains Rider using FastReport .NET.
What do you need to get started? At least, you need to have the JetBrains Rider IDE installed on your PC. And also take into account the Linux features and make additional settings.
First of all, for Linux, we need additional libraries that may not be installed by default:

  • libgdiplus;
  • libx11-dev.

Linux setup with the example of Ubuntu 22.04.1 LTS:

1. Open console;
2. Update apt-get and install packages:

    • sudo apt-get update;
    • sudo apt-get install libgdiplus;

Next, create a new solution by selecting “New Solution”.

Welcome form of IDE JetBrains Rider

The next step is to set up the project. Select the Console Application project type in the .NET/.NET Core section. Then we give a name to the project, as an example, we use "ReportPDF_Core_ConsoleApp." After we click on the Console Application type, C# language, NET 6.0 framework.

Project setup form before creation

Let's start by adding a simple sample dataset for our report in our application code. To do this, add to Program.cs:

 using System.Data;

Let's add a variable next:

// creating a dataset set 
DataSet dataSet = new DataSet();

Let's add the CreateDataSet function, in which we will create and fill in the data set:

void CreateDataSet()
{
// create a simple dataset with one table
// create a simple dataset
dataSet = new DataSet();
 
// create a table
DataTable table = new DataTable();
table.TableName = "Employees";
// adding a table to the dataset
dataSet.Tables.Add(table);
 
// adding data to a table
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Name", typeof(string));
table.Rows.Add(1, "Andrew Fuller");
table.Rows.Add(2, "Nancy Davolio");
table.Rows.Add(3, "Margaret Peacock");
}

And add a call to the CreateDataSet function:

//creating a dataset object
DataSet dataSet = new DataSet();
CreateDataSet();

What is the easiest way to get FastReport .NET working in JetBrains Rider? To use our Private NuGet-server from Fast Reports.

This article describes how to add NuGet packages after purchasing FastReport .NET. Here is a brief instruction so as not to search for another article. Click on the NuGet tab at the bottom of the IDE, and click on the Sources tab.

NuGet settings form

Now we add a new repository by clicking on the "+" and enter the necessary data:

- Name—source name without spaces (for example FastReport);
- URL—https://nuget.fast-report.com/api/v3/index.json;
- User—email from Fast Reports account;
- Password—password from Fast Reports account.

Form for adding a NuGet repository

You will see the repository:

FastReport-NuGet repository has been added

We will now install the FastReport Core package. To do this, go to the Packages tab and filter the packages by the FastReport repository. And of course, install the found package.

Installing the FastReport.Core NuGet package

If it was successful, you will receive a notification.

Notification about the successful installation of the FastReport.Core NuGet package

Next, let’s create a template from the code, for this we will do the following. Add to Program.cs:

using System.Drawing;
using FastReport;
using FastReport.Export.Pdf;
using FastReport.Utils;

Next, add CreateDataSet to Program.cs below:

Report report = new Report();
CreateReportTemplate();
ExportToPDF();

Then add the function for creating a report template CreateReportTemplate:

void CreateReportTemplate()
{
 // adding a report page
 ReportPage page = new ReportPage();
 
 // creating a date band
 DataBand data = new DataBand();
 PageHeaderBand dataText = new PageHeaderBand();
 
 //creating a header
 ReportTitleBand titleBand = new ReportTitleBand();
 TextObject employeeIdText = new TextObject();
 TextObject employeeNameText = new TextObject();
 TextObject idText = new TextObject();
 TextObject nameText = new TextObject();
 TextObject titleText = new TextObject();
 //registering the data source
 report.RegisterData(dataSet);
 //enabling on the data table
 report.GetDataSource("Employees").Enabled = true;
 //adding a page to the template
 report.Pages.Add(page);
 // add to the page: data,data Text, titleBand
 // and set the unique name of the page
 page.AddChild(data);
 page.AddChild(dataText);
 page.AddChild(titleBand);
 page.CreateUniqueName();
 // set the unique name titleBand
 // and set the band settings
 titleBand.CreateUniqueName();
 titleBand.Height = Units.Centimeters * 1.5f;
 titleText.Bounds = new RectangleF(300, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
 titleText.Text = "Employees";
 titleText.Font = new Font("Arial", 14, FontStyle.Bold);
 titleText.VertAlign = VertAlign.Center;
 
 // set the unique name data
 // and set the data settings
 data.CreateUniqueName();
 data.DataSource = report.GetDataSource("Employees");
 data.Height = Units.Centimeters * 0.5f;
 
 // set a unique dataText name
 // and set the dataText settings
 dataText.CreateUniqueName();
 dataText.Height = Units.Centimeters * 0.8f;
 
 // setting the unique name employeeIdText
 // and set the employeeIdText, idText settings
 employeeIdText.Parent = data;
 employeeIdText.CreateUniqueName();
 employeeIdText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
 idText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
 idText.Text = "ID";
 employeeIdText.Text = "[Employees.ID]";
 
 // set the unique name employeeNameText
 // and set the employeeNameText, nameText settings
 employeeNameText.Parent = data;
 employeeNameText.CreateUniqueName();
 employeeNameText.Bounds = new RectangleF(50, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
 nameText.Bounds = new RectangleF(50, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
 nameText.Text = "Name";
 employeeNameText.Text = "[Employees.Name]";
 
 // add on data band: employeeIdText, employeeNameText
 data.AddChild(employeeIdText);
 data.AddChild(employeeNameText);
 
 // add on dataText band: idText, nameText
 dataText.AddChild(idText);
 dataText.AddChild(nameText);
 
 // add on titleBand band: itleText
 titleBand.AddChild(titleText);
}

Next, add the function to create an ExportToPDF report template and name the report export "Report.pdf":

void ExportToPDF()
{
 // running the report
 report.Prepare();
 // creating an export instance
 PDFExport export = new PDFExport();
 report.Export(export, "test.pdf");
 // disposing the resources used by the report
 report.Dispose(); 
}

Let's start the console application. If you received the response Process finished with exit code 0, then you did everything right, open the report, in our case, it is the path /home/alex/RiderProjects/ReportPDF_Core_ConsoleApp/ReportPDF_Core_ConsoleApp/bin/Debug/net6.0/test.pdf:

 The result of the PDF export of the report

Thus, we got a simple report/PDF document built from a dataset.

In this article, we have discussed the binding JetBrains Rider (C#) + .NET Core + Console Application + FastReport .NET Core + Linux (Ubuntu 22.04.1 LTS) and got a report built from a PDF dataset. And of course, we made sure that the .NET platform can be easily used without Microsoft Visual Studio since Linux simply does not have it.

Of course, we have not told you about creating a GUI application on Linux, which can, for example, be done using the Mono framework, but you can find articles on how to do this on our site.

Full program listing

using System.Data;
using System.Drawing;
using FastReport;
using FastReport.Export.Pdf;
using FastReport.Utils;
 
//creating a data set 
DataSet dataSet = new DataSet();
CreateDataSet();
//creating a report
Report report = new Report();
 
CreateReportTemplate();
ExportToPDF();
 
void CreateReportTemplate()
{
 // add a report page
 ReportPage page = new ReportPage();
 
 // create a data band
 DataBand data = new DataBand();
 PageHeaderBand dataText = new PageHeaderBand();
 
 //create a title
 ReportTitleBand titleBand = new ReportTitleBand();
 TextObject employeeIdText = new TextObject();
 TextObject employeeNameText = new TextObject();
 TextObject idText = new TextObject();
 TextObject nameText = new TextObject();
 TextObject titleText = new TextObject();
 //register a data source
 report.RegisterData(dataSet);
 //enable a data table
 report.GetDataSource("Employees").Enabled = true;
 //add a page to the template
 report.Pages.Add(page);
 //add on a page: data,dataText, titleBand
 // and set the unique page name
 page.AddChild(data);
 page.AddChild(dataText);
 page.AddChild(titleBand);
 page.CreateUniqueName();
 // set the unique name titleBand
 // and set the band settings
 titleBand.CreateUniqueName();
 titleBand.Height = Units.Centimeters * 1.5f;
 titleText.Bounds = new RectangleF(300, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
 titleText.Text = "Employees";
 titleText.Font = new Font("Arial", 14, FontStyle.Bold);
 titleText.VertAlign = VertAlign.Center;
 
 // create the unique data name
 // and set the data settings
 data.CreateUniqueName();
 data.DataSource = report.GetDataSource("Employees");
 data.Height = Units.Centimeters * 0.5f;
 
 // create a unique dataText name
 // and set dataText settings
 dataText.CreateUniqueName();
 dataText.Height = Units.Centimeters * 0.8f;
 
 // create the unique employeeIdText name
 // and set the employeeIdText, idText settings
 employeeIdText.Parent = data;
 employeeIdText.CreateUniqueName();
 employeeIdText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
 idText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
 idText.Text = "ID";
 employeeIdText.Text = "[Employees.ID]";
 
 // create the unique name employeeNameText 
 // and set the employeeNameText, nameText settings
 employeeNameText.Parent = data;
 employeeNameText.CreateUniqueName();
 employeeNameText.Bounds = new RectangleF(50, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
 nameText.Bounds = new RectangleF(50, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
 nameText.Text = "Name";
 employeeNameText.Text = "[Employees.Name]";
 
 // and add on data band: employeeIdText, employeeNameText
 data.AddChild(employeeIdText);
 data.AddChild(employeeNameText);
 
 // add on dataText band: idText, nameText
 dataText.AddChild(idText);
 dataText.AddChild(nameText);
 
 // add on titleBand band: itleText
 titleBand.AddChild(titleText);
}
 
void ExportToPDF()
{
 report.Prepare();
 PDFExport export = new PDFExport();
 report.Export(export, "test.pdf");
 report.Dispose(); 
}
 
void CreateDataSet()
{
 // create a simple dataset with a single table
 
 // create a simple dataset
 dataSet = new DataSet();
 
 // create a table
 DataTable table = new DataTable();
 table.TableName = "Employees";
 // add the table to dataset
 dataSet.Tables.Add(table);
 
 // add data to the table
 table.Columns.Add("ID", typeof(int));
 table.Columns.Add("Name", typeof(string));
 table.Rows.Add(1, "Andrew Fuller");
 table.Rows.Add(2, "Nancy Davolio");
 table.Rows.Add(3, "Margaret Peacock");
}
December 19, 2022

Creating a PDF report in JetBrains Rider (C#) in Windows 11

In this article we will take a look at .NET in Windows 11 without using Microsoft Visual Studio, and export the report to PDF format.
September 06, 2022

The era of WinForms is over, the era of FastReport.Core.Skia began

The new Sharp graphics engine for creating high-quality reports and correctly exporting to different formats is available in FastReport .NET.
November 17, 2021

Application with FastReport .NET in Docker with Linux

Docker executes unfolding with literally two commands, while containers take much less space than the virtual machine images.
Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 66 Canal Center Plaza, Ste 505, Alexandria, VA 22314

© 1998-2024 Fast Reports Inc.