public static void ExportToPdf(this Report report, string path) { using (PdfSurface pdfSurface = new PdfSurface( path, report.WidthWithMargins, report.HeightWithMargins)) { Cairo.Context cr = new Cairo.Context(pdfSurface); cr.Translate(report.Margin.Left, report.Margin.Top); ReportRenderer renderer = new ReportRenderer() { Context = cr }; renderer.RegisterRenderer(typeof(TextBlock), new TextBlockRenderer()); renderer.RegisterRenderer(typeof(Line), new LineRenderer()); renderer.RegisterRenderer(typeof(Image), new ImageRenderer() { PixbufRepository = new PixbufRepository(report.ResourceRepository) }); SectionRenderer sr = new SectionRenderer(); renderer.RegisterRenderer(typeof(ReportHeaderSection), sr); renderer.RegisterRenderer(typeof(ReportFooterSection), sr); renderer.RegisterRenderer(typeof(DetailSection), sr); renderer.RegisterRenderer(typeof(PageHeaderSection), sr); renderer.RegisterRenderer(typeof(PageFooterSection), sr); MonoReports.Model.Engine.ReportEngine engine = new MonoReports.Model.Engine.ReportEngine(report, renderer); engine.Process(); for (int i = 0; i < report.Pages.Count; ++i) { renderer.RenderPage(report.Pages [i]); cr.ShowPage(); } pdfSurface.Finish(); (cr as IDisposable).Dispose(); } }
public MonoreportsDesignerControl() { Build(); dpi = Gdk.Screen.Default.Resolution; Report startReport = new Report() { DataScript = @" datasource = new [] { new { Name=""Alfred"", Surname = ""Tarski"", Age = ""82"" }, new { Name=""Saul"", Surname = ""Kripke"", Age = ""70"" }, new { Name=""Gotlob"", Surname = ""Frege"", Age = ""85"" }, new { Name=""Kurt"", Surname = ""Gödel"", Age = ""72"" }, }; parameters.Add(""Title"",new { Title = ""The Logicans"", SubTitle = ""...and philosophers...""}); " }; string template = @" using System; using System.Collections.Generic; {0} public sealed class GenerateDataSource {{ public object Generate() {{ object datasource = null; Dictionary<string,object> parameters = new Dictionary<string,object>(); {1} return new object[] {{datasource,parameters}}; }} }} "; compilerService = new CompilerService(template); workspaceService = new WorkspaceService(this, maindesignview1.DesignDrawingArea, maindesignview1.PreviewDrawingArea, mainPropertygrid, StatusBarLabel); designService = new DesignService(workspaceService, compilerService, startReport); toolBoxService = new ToolBoxService(); designService.ToolBoxService = toolBoxService; maindesignview1.DesignService = designService; maindesignview1.WorkSpaceService = workspaceService; maindesignview1.Compiler = compilerService; var reportRenderer = new ReportRenderer(); reportRenderer.RegisterRenderer(typeof(Controls.TextBlock), new TextBlockRenderer() { DPI = dpi }); reportRenderer.RegisterRenderer(typeof(Controls.Line), new LineRenderer() { DPI = dpi }); reportRenderer.RegisterRenderer(typeof(MonoReports.Model.Controls.Image), new ImageRenderer() { PixbufRepository = designService.PixbufRepository, DPI = dpi }); SectionRenderer sr = new SectionRenderer() { DPI = dpi }; reportRenderer.RegisterRenderer(typeof(Controls.ReportHeaderSection), sr); reportRenderer.RegisterRenderer(typeof(Controls.ReportFooterSection), sr); reportRenderer.RegisterRenderer(typeof(Controls.DetailSection), sr); reportRenderer.RegisterRenderer(typeof(Controls.PageHeaderSection), sr); reportRenderer.RegisterRenderer(typeof(Controls.PageFooterSection), sr); maindesignview1.ReportRenderer = reportRenderer; workspaceService.InvalidateDesignArea(); reportExplorer.DesignService = designService; reportExplorer.Workspace = workspaceService; toolBoxService.AddTool(new ZoomTool(designService)); toolBoxService.AddTool(new LineTool(designService)); toolBoxService.AddTool(new LineToolV(designService)); toolBoxService.AddTool(new LineToolH(designService)); toolBoxService.AddTool(new TextBlockTool(designService)); toolBoxService.AddTool(new SubreportTool(designService)); toolBoxService.AddTool(new SectionTool(designService)); toolBoxService.AddTool(new ImageTool(designService)); toolBoxService.AddTool(new RectTool(designService)); toolBoxService.BuildToolBar(mainToolbar); ToolBarButton exportPdfToolButton = new ToolBarButton("pdf.png", "exportPdf", "export to pdf"); exportPdfToolButton.Clicked += delegate(object sender, EventArgs e) { designService.ExportToPdf(); }; mainToolbar.Insert(exportPdfToolButton, 7); mainPropertygrid.LoadMonoreportsExtensions(); }