Hi,
I am creating a report that will have multiple sections in it. Each section will have a different header. Part of the header is the same throughout the pdf so I created a table and use that in the header.
I'm not sure what I am doing wrong but the text in the table looks like it is being written twice. Here is some code that can recreate the problem. Thanks for your help.
string [] strHeadings = new string [] {"one", "two_two", "three\nfour", "five", "six\nseven", "eight", "nine", "10", "11", "12\n13"};
//create table to be used in header
Table headerTable = new Table();
//borders
headerTable.DefaultCellBorder = new BorderInfo((int)BorderSide.Bottom | (int)BorderSide.Top ,1.0F);
//text info
headerTable.DefaultCellTextInfo = tiBold;
headerTable.ColumnWidths = "50 50 50 50 50 50 50 50 50 50";
//fill heading cells
Row rowItem = new Row(headerTable);
rowItem.DefaultCellTextInfo = tiBold;
for (int i = 0; i < 10; i++)
{
//only use non empty columns
Cell cell = new Cell(rowItem);
cell.DefaultCellTextInfo.Alignment = AlignmentType.Center;
cell.VerticalAlignment = VerticalAlignmentType.Bottom;
cell.DefaultCellTextInfo = tiBold;
Text cellText = new Text(strHeadings.Replace('_',' '));
cell.Paragraphs.Add(cellText);
rowItem.Cells.Add(cell);
}
//Attach to Table
headerTable.Rows.Add(rowItem);
//create another section
Section section2 = this._pdfDoc.Sections.Add();
section2.PageInfo.Margin.Top = 30;
section2.PageInfo.Margin.Bottom = 30;
section2.PageInfo.Margin.Left = 30;
section2.PageInfo.Margin.Right = 30;
section2.PageInfo.PageHeight = PageSize.LetterHeight;
section2.PageInfo.PageWidth = PageSize.LetterWidth;
section2.IsLandscape = true;
//CreateHeader
HeaderFooter headerTitle = new HeaderFooter(section2);
section2.OddHeader = section2.EvenHeader = headerTitle;
headerTitle.Margin.Top = 15;
headerTitle.Margin.Bottom = 10;
//Create the Title text
Text textTitle = new Text("This is the Title\nTwo Lines");
textTitle.TextInfo = tiBold;
textTitle.TextInfo.Alignment = AlignmentType.Center;
headerTitle.Paragraphs.Add(textTitle);
//Add Header table
headerTitle.Paragraphs.Add(headerTable);
//new table
Table tableBody2 = new Table(section2);
tableBody2.ColumnWidths = "100 100 100 100 100";
tableBody2.DefaultCellBorder = new BorderInfo((int)BorderSide.All,1.0F);
tableBody2.DefaultCellTextInfo = tiCenter;
tableBody2.DefaultCellPadding.Bottom = tableBody2.DefaultCellPadding.Left
= tableBody2.DefaultCellPadding.Right = tableBody2.DefaultCellPadding.Top = 2;
Row rowItem2 = new Row(tableBody2);
rowItem2.Cells.Add("One").VerticalAlignment = VerticalAlignmentType.Bottom;
rowItem2.Cells.Add("Two");
rowItem2.Cells.Add("Vend\r\nItem");
rowItem2.Cells.Add("Four");
rowItem2.Cells.Add("Five").VerticalAlignment = VerticalAlignmentType.Center;
tableBody2.Rows.Add(rowItem2);
section2.AddParagraph(tableBody2);