PDF Report Generation

Jan 14, 2013 at 8:46 AM

Hi.

I'm having difficulties in getting the report generation framework to work. I've tried following the example in the ExportDemo but cannot get it to work. I'm using OxyPlot NET40 2013.1.7.1.

When calling my method below, it does not generate the expected output (no report.pdf file) but a file for the model plot IS generated.

Am I missing something in my report structure or is there some initialization that should be performed before writing the report ?

Here is the code. 

	public static void GenerateReport()
	{
		try
		{
			var r = new Report();
			r.Title = "Test Report";
			
			r.AddHeader(1, "Sensor Data");
			var main = new ReportSection();
			r.AddParagraph("Pressure Data");
			
			PlotModel presModel = PlotTimedData(data[0], data[3], "Pressure [Bar]");
			main.AddPlot(presModel, "Pressure", 300, 200);

			r.Add(main);
			
			ReportStyle style = new ReportStyle();			
			PdfReportWriter w = new PdfReportWriter(@"c:\data\report.pdf");
			
			w.WriteReport(r, style);
		}
		catch (Exception e)
		{
			Console.WriteLine("Failed to create report: " + e.Message);
			Console.WriteLine(e.StackTrace);
		}
	}

Coordinator
Jan 22, 2013 at 9:40 AM
Edited Jan 22, 2013 at 9:42 AM

I think you need to call Close on the PdfReportWriter.

Or better, use a "using" block:

using (var w = new PdfReportWriter(@"c:\data\report.pdf")) w.WriteReport(r, style);

I see the API needs to be cleaned up a bit here, to avoid confusion.

I think I will change to something like the static syntax used in System.IO.File (http://msdn.microsoft.com/en-us/library/system.io.file.writealltext.aspx)

PdfReportWriter.Export(r, style, @"c:\data\report.pdf");

See http://oxyplot.codeplex.com/workitem/10023