コード例 #1
0
        static void PdfWithTable()
        {
            // Table
            PdfTable table = new PdfTable(
                style: TableStyle.OnlyRowsBordered,
                fitToDocument: true);

            // THead
            table.THead.Add(new PdfTableHeaderCell("Nummer", Alignment.Left, 2.0));
            table.THead.Add(new PdfTableHeaderCell("Name", Alignment.Left, 4.0));
            table.THead.Add(new PdfTableHeaderCell("Position", Alignment.Left, 2.0));
            table.THead.Add(new PdfTableHeaderCell("GP", Alignment.Center, 2.0));
            table.THead.Add(new PdfTableHeaderCell("G", Alignment.Center, 2.0));
            table.THead.Add(new PdfTableHeaderCell("A", Alignment.Center, 2.0));
            table.THead.Add(new PdfTableHeaderCell("PTS", Alignment.Center, 2.0));
            table.THead.Add(new PdfTableHeaderCell("PIM", Alignment.Center, 2.0));

            // TBody
            PdfTableRow row = new PdfTableRow();

            row.Add(new PdfTableCell("1"));
            row.Add(new PdfTableCell("Aebischer David"));
            row.Add(new PdfTableCell("Goalkeeper"));
            row.Add(new PdfTableCell("65"));
            row.Add(new PdfTableCell("0"));
            row.Add(new PdfTableCell("0"));
            row.Add(new PdfTableCell("0"));
            row.Add(new PdfTableCell("14"));

            table.TBody.Add(row);

            row = new PdfTableRow();

            row.Add(new PdfTableCell("1"));
            row.Add(new PdfTableCell("Aeschlimann Jean-Jaques"));
            row.Add(new PdfTableCell("Forwarder"));
            row.Add(new PdfTableCell("120"));
            row.Add(new PdfTableCell("20"));
            row.Add(new PdfTableCell("15"));
            row.Add(new PdfTableCell("35"));
            row.Add(new PdfTableCell("24"));

            table.TBody.Add(row);

            IPdfTemplate template = new PdfTemplateWithHeaderAndHeading();

            template.Define(
                title: "U20 Junior National Team 2 2 2 2 2 2 2 2 2 2",
                author: "Doc Author",
                subject: "PLAYER STATISTICS - Season 2014 / 2015",
                keywords: "Doc Keywords",
                absolutePathToPdfTemplate: @"D:\DEVELOPMENT\GIT\OPTEN Solutions\tools\Pdf\pdf_template.pdf");

            template.Elements.Add(table);

            // Create
            template.SaveOnDisk(@"C:\Users\cfrei\Desktop\" + template.FileName());
        }
コード例 #2
0
        public RowRenderer(PdfTableRow row)
        {
            Row = row;

            foreach (var cell in Row.Cells)
            {
                _cellRenderers.Add(new CellRenderer(cell));
            }
        }
コード例 #3
0
        /// <summary>
        /// Renders the specified PDF styling.
        /// </summary>
        /// <param name="pdfStyling">The PDF styling.</param>
        /// <param name="section">The section.</param>
        public void Render(IPdfStyling pdfStyling, Section section)
        {
            PdfTable table = new PdfTable(
                style: TableStyle.NoSpacing,
                fitToDocument: true);

            // Title rows
            foreach (string title in _titles)
            {
                table.THead.Add(new PdfTableHeaderCell(title.Trim(), true, Alignment.Left));
            }

            // Get the max count

            int maxCount = _addresses.Max(o => o.Count());

            PdfTableRow row;

            string line;
            bool   isBold;

            for (int i = 0; i < maxCount; i++)
            {
                row = new PdfTableRow();
                foreach (IEnumerable <TextLine> addressLine in _addresses)
                {
                    line   = i >= addressLine.Count() ? string.Empty : addressLine.ElementAt(i).Text;
                    isBold = i >= addressLine.Count() ? false : addressLine.ElementAt(i).IsBold;

                    row.Add(new PdfTableCell(text: line, isBold: isBold));
                }

                table.TBody.Add(row);
            }

            table.Render(pdfStyling: pdfStyling, section: section);
        }
コード例 #4
0
        private void AddCell(
            IPdfStyling pdfStyling,
            MigraDoc.DocumentObjectModel.Tables.Table table,
            PdfTableRow pdfRow,
            bool isTFoot)
        {
            // Each item fills one row
            Row row = table.AddRow();

            row.TopPadding = Unit.FromPoint(5);
            //row.BottomPadding = Unit.FromPoint(2);

            IPdfTableCell pdfCell;
            int           pdfCellIndex, pdfCellIndexWithColspan;

            for (int j = 0; j < pdfRow.Cells.Count; j++)
            {
                pdfCellIndex            = j;
                pdfCellIndexWithColspan = pdfCellIndex;
                pdfCell = pdfRow.Cells[j];

                if (pdfCellIndex > 0)
                {
                    // If we have a colspan we have to update the index
                    // http://www.pdfsharp.net/wiki/invoice-sample.ashx
                    for (int y = 0; y < pdfCellIndex; y++)
                    {
                        if (pdfRow.Cells[y].Colspan > 1)
                        {
                            pdfCellIndexWithColspan += pdfRow.Cells[y].Colspan - 1;
                        }
                    }
                }

                AddText(
                    pdfStyling: pdfStyling,
                    pdfCell: pdfCell,
                    cell: row.Cells[pdfCellIndexWithColspan]);

                row.Cells[pdfCellIndexWithColspan].VerticalAlignment = VerticalAlignment.Top;

                if (pdfCell.Alignment != Alignment.Inherit)
                {
                    row.Cells[pdfCellIndexWithColspan].Format.Alignment = pdfCell.Alignment.GetAlignment();
                }

                if (pdfCell.Colspan > 1)
                {
                    row.Cells[pdfCellIndexWithColspan].MergeRight = pdfCell.Colspan - 1;
                }

                if (isTFoot)
                {
                    row.Cells[pdfCellIndexWithColspan].Style = PdfStyleNames.Table.TFoot;
                }
                else
                {
                    row.Cells[pdfCellIndexWithColspan].Style = PdfStyleNames.Table.TBody;
                }
            }
        }
コード例 #5
0
        private static void AddTestTable(PdfPage page)
        {
            var table = new PdfTable(page, 10, 100);

            PdfTableCell cell;
            PdfTableRow  row;

            for (int i = 0; i < 3; i++)
            {
                row = new PdfTableRow(table);

                if (i == 2)
                {
                    row.BackColor = Color.FromArgb(246, 246, 255);
                }

                cell = new PdfTableCell(row, 123456.78, "{0:#,####.00}", true)
                {
                    Font = new Font
                    {
                        TextSize   = 10,
                        FontFamily = Fonts.Arial,
                    },

                    Width           = 100,
                    ForeColor       = Color.Red,
                    DrawRightBorder = true,

                    TextJustify = TextJustify.Right
                };

                row.AddCell(cell);

                string text = "Hello";

                if (i == 0)
                {
                    text = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";
                }

                cell = new PdfTableCell(row, text, string.Empty, false)
                {
                    Font = new Font
                    {
                        TextSize   = 10,
                        FontFamily = Fonts.Arial,
                    }
                };

                if (i == 0)
                {
                    cell.Font.TextSize = 6;
                }

                cell.Width = 200;

                if (i == 2)
                {
                    cell.DrawRightBorder = true;
                    cell.TextJustify     = TextJustify.Center;
                }

                row.AddCell(cell);

                cell = new PdfTableCell(row, "World", string.Empty, false)
                {
                    Font = new Font
                    {
                        TextSize   = 10,
                        FontFamily = Fonts.Arial,
                    },

                    Width = 50
                };

                if (i == 1)
                {
                    cell.TextJustify = TextJustify.Center;
                }

                row.AddCell(cell);

                row.Width = 350;
                table.Rows.Add(row);
            }

            page.PageElements.Add(table);
        }