Exemplo n.º 1
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();
     }
 }
Exemplo n.º 2
0
        public 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 e)
            {
                Console.WriteLine("PdfExporter.GeneratePdf. Exception: {0}", e);
                return(false);
            }
        }
Exemplo n.º 3
0
        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();
        }