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 Main(string[] args) { // call the snippets Snippets snip = new Snippets(); Surface surface = new PdfSurface("snippets.pdf", IMAGE_WIDTH, IMAGE_WIDTH); Context cr = new Context(surface); foreach (string snippet in Snippets.snippets) { cr.Save(); Snippets.InvokeSnippet(snip, snippet, cr, IMAGE_WIDTH, IMAGE_HEIGHT); cr.ShowPage (); cr.Restore(); } surface.Finish (); }
public static bool GeneratePdf(Game [] games, int games_page, string file) { int columns, rows; switch (games_page) { case 1: columns = 1; rows = 1; break; case 2: columns = 2; rows = 1; break; case 4: columns = 2; rows = 2; break; default: throw new InvalidOperationException ("Invalid games per page value"); } try { PdfSurface pdf = new PdfSurface (file, page_width * columns, page_height * rows); if (pdf.Status != Status.Success) return false; CairoContextEx cr = new CairoContextEx (pdf, "sans 12", 72); GenerateQuestions (cr, games, columns, rows); GenerateAnswers (cr, games, columns, rows); pdf.Finish (); ((IDisposable)cr).Dispose(); return true; } catch (Exception) { return false; } }
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; }