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 ();
     }
 }
Exemple #2
0
 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 static void ExportToPdf(this Report report ,string path)
        {
            report.EvalDataSource();
            double unitMultiplier = CairoExtensions.UnitMultiplier;
            double realFontMultiplier = CairoExtensions.RealFontMultiplier;
            ReportRenderer renderer = new ReportRenderer ();
            renderer.ResolutionX = 72;

            using (PdfSurface pdfSurface = new PdfSurface (
                path,report.WidthWithMargins * renderer.UnitMultipilier,
                report.HeightWithMargins * renderer.UnitMultipilier)) {

                Cairo.Context cr = new Cairo.Context (pdfSurface);
                cr.Antialias = Antialias.None;
                renderer.Context = cr;
                renderer.RegisterRenderer (typeof(TextBlock), new TextBlockRenderer ());
                renderer.RegisterRenderer (typeof(Line), new LineRenderer ());
                PixbufRepository pbr = new PixbufRepository();
                pbr.Report = report;

                renderer.RegisterRenderer (typeof(Image), new ImageRenderer (){PixbufRepository = pbr});
                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 ();

                Cairo.Context cr1 = new Cairo.Context (pdfSurface);
                renderer.Context = cr1;
                cr1.Translate(report.Margin.Left * renderer.UnitMultipilier,report.Margin.Top * renderer.UnitMultipilier);
                engine.RenderPages(renderer,report);
                pdfSurface.Finish ();
                (cr as IDisposable).Dispose ();
                (cr1 as IDisposable).Dispose ();
            }

            CairoExtensions.UnitMultiplier = unitMultiplier;
            CairoExtensions.RealFontMultiplier = realFontMultiplier;
        }