예제 #1
0
        /// <summary>
        /// Paint the report
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            PdfSharp.Pdf.PdfDocument   document = new PdfSharp.Pdf.PdfDocument();
            PdfSharp.Drawing.XGraphics xg;

            Graphics g2D     = e.Graphics;
            Bitmap   drawing = null;

            drawing = new Bitmap(this.Width, this.Height, e.Graphics);
            g2D     = Graphics.FromImage(drawing);
            g2D.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);
            RectangleF bounds = g2D.VisibleClipBounds;
            SolidBrush brush  = new SolidBrush(COLOR_BACKGROUND);   //background color filling

            g2D.FillRectangle(brush, bounds.X, bounds.Y, bounds.Width, bounds.Height);
            for (int page = 0; page < m_layout.GetPages().Count(); page++)
            {
                Rectangle pageRectangle = GetRectangleOfPage(page + 1);
                if (bounds.IntersectsWith(pageRectangle))
                {
                    PdfSharp.Pdf.PdfPage pdfpage = document.AddPage();
                    pdfpage.Height = pageRectangle.Height;
                    pdfpage.Width  = pageRectangle.Width;
                    xg             = PdfSharp.Drawing.XGraphics.FromPdfPage(pdfpage);

                    Page p = (Page)m_layout.GetPages()[page];
                    p.PaintPdf(xg, pageRectangle, true, false);         //	sets context
                    m_layout.GetHeaderFooter().PaintPdf(xg, pageRectangle, true);
                    //p.Paint(g2D, pageRectangle, true, false);		//	sets context
                    //m_layout.GetHeaderFooter().Paint(g2D, pageRectangle, true);
                }
            }

            document.Save("D:\\Saved.pdf");
            document.Close();

            e.Graphics.DrawImageUnscaled(drawing, 0, 0);
            brush.Dispose();
            g2D.Dispose();
            this.AutoScrollMinSize = new System.Drawing.Size(this.GetPaperWidth(), this.GetPaperHeight() * m_layout.GetPages().Count() + (m_layout.GetPages().Count() * 5) + 10);
        }