protected virtual void DefineTables(Document document, Report report)
        {
            ReportRowCollection rptrows = report.GetRows();
            int rowCount = rptrows.Count;

            if (rowCount <= 1)
            {
                return;
            }

            Table table = new Table();

            table.Format.Alignment = ParagraphAlignment.Center;
            table.Borders.Width    = 0.75;


            ReportRow headerRow   = rptrows[0];
            int       columnCount = 0;

            foreach (RowField field in headerRow.Fields)
            {
                columnCount++;
            }


            Unit      columnWidth = 100;
            PageSetup pageSetup   = document.DefaultPageSetup;

            if (Landscape)
            {
                columnWidth = (pageSetup.PageHeight - pageSetup.TopMargin - pageSetup.BottomMargin) / columnCount;
            }
            else
            {
                columnWidth = (pageSetup.PageWidth - pageSetup.LeftMargin - pageSetup.RightMargin) / columnCount;
            }


            foreach (RowField field in headerRow.Fields)
            {
                table.AddColumn(columnWidth);
            }

            int  columnIndex = 0;
            Row  row         = table.AddRow();
            Cell cell        = null;

            row.Shading.Color = Colors.PaleGoldenrod;
            foreach (RowField field in headerRow.Fields)
            {
                cell = row.Cells[columnIndex++];
                cell.AddParagraph(field.HeaderText);
            }

            for (int rowIndex = 1; rowIndex < rowCount; ++rowIndex)
            {
                ReportRow rptrow = rptrows[rowIndex];
                row = table.AddRow();

                if (rptrow.RowType == ReportRowType.DataRow)
                {
                    columnIndex = 0;
                    foreach (RowField field in rptrow.Fields)
                    {
                        cell = row.Cells[columnIndex++];
                        cell.AddParagraph(rptrow.GetFormattedValue(field));
                    }
                }
            }

            document.LastSection.Add(table);
        }
示例#2
0
        protected virtual void BuildReportHtml(ReportTextFieldCollection textFields, RenderHintsCollection hints, ReportRowCollection rows)
        {
            RenderHeader(textFields, hints);
            bool isFirstDataRow = true;

            foreach (ReportRow row in rows)
            {
                if (row.RowType == ReportRowType.HeaderRow)
                {
                    Html.AppendLine("<thead>");
                }
                else if (row.RowType == ReportRowType.FooterRow)
                {
                    Html.AppendLine("<tfoot>");
                }
                else if (row.RowType == ReportRowType.DataRow && isFirstDataRow)
                {
                    Html.AppendLine("<tbody>");
                    isFirstDataRow = false;
                }



                RenderRow(row, hints);


                if (row.RowType == ReportRowType.HeaderRow)
                {
                    Html.AppendLine("</thead>");
                }
                else if (row.RowType == ReportRowType.FooterRow)
                {
                    Html.AppendLine("</tfoot>");
                }
            }


            Html.AppendLine("</tbody>");

            RenderFooter(textFields, hints);
        }
示例#3
0
        public PdfDocument BuildDocument(ReportTextFieldCollection textFields, RenderHintsCollection hints, ReportRowCollection rows)
        {
            Document = hints.Orientation == ReportOrientation.Portrait ? new PdfDocument(ReportOrientation.Portrait) : new PdfDocument();


            Document.Font     = Document.AddFont("Helvetica");
            Document.FontSize = 6;



            XRect  docCoords = Document.Rect;
            double height    = Document.Rect.Height;
            double width     = Document.Rect.Width;

            Document.Rect.Inset(10, 40);
            Document.Rect.Height = Document.Rect.Height - 50;

            int fieldCount = 0;

            if (rows[0] != null)
            {
                fieldCount = rows[0].Fields.Count(f => f.Hidden == false);
            }

            var table = new PDFTable(Document, fieldCount)
            {
                CellPadding  = 5,
                RepeatHeader = true
            };


            if (hints.ContainsKey("PdfWidths"))
            {
                double[] widths = hints["PdfWidths"] as double[];
                table.SetColumnWidths(widths);
            }


            foreach (ReportRow row in rows)
            {
                table.NextRow();

                int cellIndex = 0;

                foreach (RowField field in row.Fields)
                {
                    table.NextCell();

                    string cellHtml;
                    if (row.RowType == ReportRowType.HeaderRow)
                    {
                        cellHtml = string.Format("<StyleRun FontSize=7><B><U>{0}</U></B></StyleRun>", field.HeaderText);
                    }
                    else
                    {
                        // TODO: Support DataRow styling, etc
                        cellHtml = row.GetFormattedValue(field);
                    }

                    table.AddHtml(cellHtml);
                    cellIndex++;
                }

                if (hints.ContainsKey("PdfUnderline"))
                {
                    if (hints["PdfUnderline"] as bool? == true)
                    {
                        table.UnderlineRow("800 800 800", table.Row);
                    }
                }
            }


            // HEADER
            Document.Rect.Position(10, height - 90);
            Document.Rect.Height = 80;
            Document.Rect.Width  = width;

            for (int i = 1; i <= Document.PageCount; i++)
            {
                Document.PageNumber = i;

                Document.AddHtml(string.Format("<h3 align='center'>{0}</h3>", textFields.Title.FormatHtml()));
                Document.AddHtml(string.Format("<h5 align='center'>{0}</h5>", textFields.SubTitle.FormatHtml()));
                Document.AddHtml(string.Format("<p><b>{0}</b></p>", textFields.Header.FormatHtml()));
            }



            // TODO: Support for sub-totals on each page, for columns that ask for totals
            // TODO: Need to add support for the Report Footer text, currently only supports page numbers

            // FOOTER
            if (hints.IncludePageNumbers)
            {
                Document.Rect.Position(10, Document.MediaBox.Bottom);
                Document.Rect.Height = 30;
                Document.Rect.Width  = width;
                Document.HPos        = 0.5;
                Document.VPos        = 0.5;

                for (int i = 1; i <= Document.PageCount; i++)
                {
                    //Document.AddBookmark("Page " + i.ToString(), true);
                    Document.PageNumber = i;
                    Document.AddText(string.Format("Page {0} of {1}", i, Document.PageCount));
                }
            }

            for (int i = 1; i <= Document.PageCount; i++)
            {
                Document.PageNumber = i;
                Document.Flatten();
            }

            return(Document);
        }