Example #1
0
        public string Render(Rdl.Render.GenericRender rpt, PageRender pageRender)
        {
            _doc        = new Document();
            _pageRender = pageRender;

            _bm         = new Bitmap(1000, 1000);
            _g          = Graphics.FromImage(_bm);
            _g.PageUnit = GraphicsUnit.Point;

            // Create the fonts used in the report.
            int ct = rpt.StyleList.Count;

            _pdfFontList = new Pdf.Font[ct];
            _winFontList = new System.Drawing.Font[ct];
            for (int i = 0; i < ct; i++)
            {
                if (rpt.StyleList[i] is TextStyle)
                {
                    TextStyle ts = rpt.StyleList[i] as TextStyle;

                    _winFontList[i] = ts.GetWindowsFont();

                    _pdfFontList[i] = new Pdf.Font(_doc, "F" + i.ToString(), _winFontList[i]);
                }
            }

            // Loop through the pages in the document rendering the pages to PDF.
            for (int pageNum = 0; pageNum < pageRender.Pages.Count; pageNum++)
            {
                Pdf.Page pdfPage = _doc.Pages.AddPage(_doc,
                                                      new Rectangle(0, 0, (int)_pageRender.PageWidth, (int)_pageRender.PageHeight));

                Page renderedPage = pageRender.Pages[pageNum];

                Pdf.ContentStream cs = pdfPage.AddContents(_doc);

                foreach (Element elmt in pageRender.Pages[pageNum].Children)
                {
                    RecurseRender(elmt, cs, pageRender.TopMargin, pageRender.LeftMargin);
                }
            }

            return(_doc.ToString());
        }
Example #2
0
        protected void RecurseRender(Element elmt, Pdf.ContentStream contents, decimal top, decimal left)
        {
            top  += elmt.Top;
            left += elmt.Left;

            if (elmt is Container || elmt is TextElement)
            {
                // If the background is not transparent then fill it in.
                if (elmt.Style != null && elmt.Style.BackgroundColor != null && elmt.Style.BackgroundColor != "transparent")
                {
                    contents.AddFillRect(left, _pageRender.PageHeight - (top + elmt.Height), left + elmt.Width, _pageRender.PageHeight - top,
                                         Rdl.Engine.Style.W32Color(elmt.Style.BackgroundColor));
                }

                // If there is a border then build the border.
                if (elmt.Style != null && elmt.Style.BorderWidth.Left.points > 0 && elmt.Style.BorderStyle.Left != Rdl.Engine.BorderStyle.BorderStyleEnum.None)
                {
                    contents.AddLine(left, _pageRender.PageHeight - (top + elmt.Height), left, _pageRender.PageHeight - top,
                                     elmt.Style.BorderWidth.Left.points,
                                     Rdl.Engine.Style.W32Color(elmt.Style.BorderColor.Left),
                                     PdfLineStyle(elmt.Style.BorderStyle.Left));
                }
                if (elmt.Style != null && elmt.Style.BorderWidth.Right.points > 0 && elmt.Style.BorderStyle.Right != Rdl.Engine.BorderStyle.BorderStyleEnum.None)
                {
                    contents.AddLine(left + elmt.Width, _pageRender.PageHeight - (top + elmt.Height), left + elmt.Width, _pageRender.PageHeight - top,
                                     elmt.Style.BorderWidth.Right.points,
                                     Rdl.Engine.Style.W32Color(elmt.Style.BorderColor.Right),
                                     PdfLineStyle(elmt.Style.BorderStyle.Right));
                }
                if (elmt.Style != null && elmt.Style.BorderWidth.Top.points > 0 && elmt.Style.BorderStyle.Top != Rdl.Engine.BorderStyle.BorderStyleEnum.None)
                {
                    contents.AddLine(left, _pageRender.PageHeight - top, left + elmt.Width, _pageRender.PageHeight - top,
                                     elmt.Style.BorderWidth.Top.points,
                                     Rdl.Engine.Style.W32Color(elmt.Style.BorderColor.Top),
                                     PdfLineStyle(elmt.Style.BorderStyle.Top));
                }
                if (elmt.Style != null && elmt.Style.BorderWidth.Bottom.points > 0 && elmt.Style.BorderStyle.Bottom != Rdl.Engine.BorderStyle.BorderStyleEnum.None)
                {
                    contents.AddLine(left, _pageRender.PageHeight - (top + elmt.Height), left + elmt.Width, _pageRender.PageHeight - (top + elmt.Height),
                                     elmt.Style.BorderWidth.Bottom.points,
                                     Rdl.Engine.Style.W32Color(elmt.Style.BorderColor.Bottom),
                                     PdfLineStyle(elmt.Style.BorderStyle.Bottom));
                }
            }

            if (elmt is TextElement)
            {
                TextElement te = elmt as TextElement;
                TextStyle   ts = te.Style as TextStyle;

                if (te.Text.Length > 0)
                {
                    decimal[]        widths;
                    CharacterRange[] charRanges = BuildCharacterRanges(
                        te.Text,
                        _winFontList[elmt.StyleIndex],
                        new Rectangle(0, 0, (int)te.Width, (int)te.Height),
                        out widths);

                    for (int i = 0; i < charRanges.Length; i++)
                    {
                        decimal l = 0, r = 0;
                        switch (ts.TextAlign)
                        {
                        case Rdl.Engine.Style.TextAlignEnum.Left:
                        case Rdl.Engine.Style.TextAlignEnum.General:
                            l = left;
                            r = l + widths[i];
                            break;

                        case Rdl.Engine.Style.TextAlignEnum.Center:
                            l = left + ((elmt.Width - widths[i]) / 2);
                            r = l + widths[i];
                            break;

                        case Rdl.Engine.Style.TextAlignEnum.Right:
                            r = left + elmt.Width;
                            l = r - widths[i];
                            break;
                        }

                        contents.AddText(l,
                                         _pageRender.PageHeight - top - (ts.LineHeight.points * (i + 1)),
                                         r,
                                         _pageRender.PageHeight - top - (ts.LineHeight.points * i),
                                         te.Text.Substring(charRanges[i].First, charRanges[i].Length),
                                         Rdl.Engine.Style.W32Color(te.Style.Color), _pdfFontList[elmt.StyleIndex],
                                         (int)ts.FontSize.points, (int)ts.LineHeight.points,
                                         null,
                                         Rdl.Pdf.ContentStream.WritingModeEnum.lr_tb,
                                         PdfFontDecofation(ts.TextDecoration));
                    }
                }
            }

            if (elmt is Container)
            {
                foreach (Element child in ((Container)elmt).Children)
                {
                    RecurseRender(child, contents, top, left);
                }
            }
        }