Posts



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.


As it seems that fyiReporting has died I have made a fork (https://github.com/majorsilence/My-FyiReporting). I have merged in patches from the fyiReporting forum. I have made build scripts to create .net 2 and .net 4 packages. I also slowly fixing bugs as I come across them. I have converted the solutions to visual studio 2008 format and fixed the references so the source code will build.

The projects should also build with no problems using visual studio express 2008 or 2010.

I have a couple reasons for this:

  1. I want to have a free reporting solution that I can use in my own projects
  2. I want a reporting solution I can run on mono/asp.net
  3. I want that reporting solution to be somewhat compatible with Microsoft reporting
  4. I need to know it is not going to disappear
  5. I want to make it easy for others to use

I currently have two bugs that I am slowly working on. The first is the RdlEngineConfig.xml file points to non-existent dlls so database support is not loaded in the designer. I think I will fix the postgresql and sqlite problem by including the required dlls in the project. For the other databases I will probably need to include any option to let users edit the paths to the dlls. The only problem with this is that it means the project will be 32bit instead of AnyCPU since sqlite is 32bit only on windows.

The second bug is that I want an designer user control that can be embedded in other applications. This means I will probably turn the current designer form into a user control and replace the current designer with a form with the new designer control added to the form.

Hopefully this will be useful to others besides myself.

Other free reporting solutions for .net: https://github.com/tomaszkubacki/monoreports https://sourceforge.net/projects/reportingcloud - this is another fork of fyiReporting but it also seems to have died


I have discovered fresh pomegranates. I wish I had tried them sooner.