Posts


This is something I have wanted to do and have been experimenting with. I have modified fyiReporting in my fork called My-FyiReporting to allow using the designer inside my own application.

My-fyiReporting is a .net report designer and viewer that is written in c#. The designer and viewer are programmed with c# and winforms. There is also a new gtk# viewer available for those that need a report viewer on Linux.

See http://files.majorsilence.com/myfyireporting/ for binary packages of My-FyiReporting. See https://github.com/majorsilence/My-FyiReporting/ for the project details and source code.

Open a Report

The simplest way to use the designer is to create an instance of the designer form and then load the report that you wish to use. If you do not have a report to open then just create an instance of the form and show it.

First add a reference to RdlDesigner.exe in your project. Then add the following code where you need to use a designer. It is as easy as that.

fyiReporting.RdlDesign.RdlDesigner designer = new fyiReporting.RdlDesign.RdlDesigner("myFyiChannel", false);
designer.Show();
designer.OpenFile(@"Path\to\a\report.rdl");

Where it is passing in myFyiChannel as a parameter is the IPC name that is being used in the designer. This must be unique or it will through an exception. You will need to handle this. I would suggest creating only one instance of the designer and show it when it is needed.

Create a new Report

If you want to create to prompt a user to create a new report you can do it like this.

DialogDatabase dlgDB = new fyiReporting.RdlDesign.DialogDatabase(this)
dlgDB.SetConnection("The Connection String", false, DialogDatabase.ConnectionType.SQLITE);
dlgDB.ShowDialog();
if (dlgDB.DialogResult == DialogResult.OK)
{
    string rdl = dlgDB.ResultReport;
    System.IO.File.WriteAllText("Path\to\new\report.rdl", dlgDB.ResultReport);
}

You can then open the new report using method described above.

See https://github.com/majorsilence/My-FyiReporting/wiki/Embed-the-Designer for more details about embedding the designer.


I have created a new fyiReporting viewer for Linux using Gtk#. It is currently very basic but will show a report. The code can be retrieved from https://github.com/majorsilence/My-FyiReporting in the RdlGtkViewer project. I have currently tested it with Ubuntu 11.10.

All issues and feature requests can be put through the projects github issues page.

It is simple to use. Add a reference to the RdlGtkViewer assembly in your project and then add the RdlGtkViewer widget to one of your forms.

Lets say I added a new instance called rdlgtkviewer1 to my project. I can load a report with parameters with the following line of code. Code:

this.rdlgtkviewer1.LoadReport(
    new Uri(@"/home/peter/Projects/My-FyiReporting/Examples/SqliteExamples/SimpleTest3WithParameters.rdl"),
    "TestParam1=Hello and Goodbye&TestParam2=Testing parameter 2"); 


It turns out that creating a pdf viewer on Linux using c# or vb.net is very easy. You will need a reference to poppler-sharp.dll.

On ubuntu install the package libpopplier-cil. There is one problem with this package; it does not show up in the reference list in MonoDevelop. So you will need to browse to the dll. On my system it was in\usr\lib\poppler-sharp\poppler-sharp.dll.

For a fully working code example see https://github.com/majorsilence/gtk-sharp-pdf-widget.

First thing you will need to do is declare a poppler document and a variable to keep track of your current page.

private Poppler.Document pdf;
private int pageIndex = 0;

The SetContinuousPageMode function will loop through everypage in the pdf, create a new gtk image to draw on then call the RenderPage function to render the page to the image and draw it to the gtk window.

private void SetContinuousPageMode()
{
	foreach (Gtk.Widget w in vboxImages.AllChildren)
	{
		vboxImages.Remove(w);
	}

	for (this.pageIndex = 0; this.pageIndex < pdf.NPages; this.pageIndex++)
	{
		Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, false, 8, 0, 0);
		Gtk.Image img = new Gtk.Image();
		img.Pixbuf = pixbuf;
		img.Name = "image1";

		//vboxImages.Add (img);
		RenderPage(ref img);
	}

	this.ShowAll();
}

The RenderPage function is the function that actually draws the pdf page to the screen. It will retrieve the page you want and set the size of image being drawn to the size of the pdf page.

private void RenderPage (ref Gtk.Image img) 
{

	Poppler.Page page = this.pdf.GetPage(this.pageIndex);
	double width=0D;
	double height=0D;
	page.GetSize(out width, out height);

	// It is important to set the image to have the correct size
	img.Pixbuf  = new  Gdk.Pixbuf (Gdk.Colorspace.Rgb, false, 8, (int)width, (int)height);
	Gdk.Pixbuf pixbuf = img.Pixbuf;
	
	page.RenderToPixbuf(0, 0, (int)width, (int)height, 1.0, 0, pixbuf);
	img.Pixbuf = pixbuf;
	vboxImages.Add (img);		
}

I plan on using this to do an initial and very basic Gtk# report viewer for My-FyiReporting.

See https://github.com/majorsilence/gtk-sharp-pdf-widget for a working example.


The My-FyiReporting fyiReporting fork is making good progress. I have the designer cleaned up enough to work with. It is now mostly done in the visual studio designer. It is possible to use the My-FyiReporting designer from other applications. All you need to do is add RdlDesigner.exe as a reference in your project. There is still some work to do on this but it is possible to use as is.

See https://github.com/majorsilence/My-FyiReporting/wiki/Embed-the-Designer for code examples of using the designer from vb.net or c#. You should also be able to use it from any .net language such as IronPython or IronRuby.

I have also fixed a bug that would stop exports to excel.

The build scripts have been updated to package some files that were being missed. The build scripts have also been updated to do 32bit and 64 bits for both .net 3.5 and .net 4.0. Currently an installation package is only for .net 3.5.

The code is available from https://github.com/majorsilence/My-FyiReporting and the readme has links to binary packages.