Example #1
0
        private static void ProcessRow(Table table, List <TableColumnDefinition> columns, List <string> data, TableStyle style)
        {
            var row = table.AddRow();

            row.VerticalAlignment = VerticalAlignment.Center;

            for (int i = 0; i < data.Count; i++)
            {
                switch (columns[i].Type)
                {
                case TableColumnType.Text:
                    var textField = row.Cells[i].AddParagraph();
                    SetParagraphStyle(textField, style);
                    textField.AddText(data[i]);
                    break;

                case TableColumnType.Image:
                    if (string.IsNullOrWhiteSpace(data[i]) || !File.Exists(data[i]))
                    {
                        throw new FileNotFoundException($"Path to header graphics was empty or the file does not exist.");
                    }

                    var logo = row.Cells[i].AddImage(data[i]);
                    logo.Height          = new Unit(columns[i].HeightInCm, UnitType.Centimeter);
                    logo.LockAspectRatio = true;
                    logo.Top             = ShapePosition.Top;
                    logo.Left            = ShapePosition.Left;
                    break;

                case TableColumnType.PageNum:
                    var pagenumField = row.Cells[i].AddParagraph();
                    SetParagraphStyle(pagenumField, style);
                    pagenumField.AddPageField();
                    pagenumField.AddText(" (");
                    pagenumField.AddNumPagesField();
                    pagenumField.AddText(")");
                    break;
                }
            }
        }