Free Support Forum - aspose.com

Problem with table in header

Hi,

I am creating a report that will contain multiple sections. Each section has a header. Part of the header is a table with one row that has verticle alignment set to centered. I am losing the verticle alignment after the first section.

Here is a sample of code that will recreate this problem. The first section is one page, the second section is three pages and the third section is one page. I am seeing the problem in the header on page 4.

string strFileName = "c:\\report.pdf";
FileStream pdfStream = new FileStream(strFileName,FileMode.Create);
Pdf pdfDoc = new Pdf(pdfStream);

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);
headerTable.ColumnWidths = "50 50 50 50 50 50 50 50 50 50";
//fill heading cells
Row rowItem = new Row(headerTable);
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.Center;
Text cellText = new Text(strHeadingsIdea.Replace('_',' '));
cell.Paragraphs.Add(cellText);
rowItem.Cells.Add(cell);
}
//Attach to Table
headerTable.Rows.Add(rowItem);

//create first section
Section section1 = pdfDoc.Sections.Add();
section1.PageInfo.Margin.Top = 30;
section1.PageInfo.Margin.Bottom = 30;
section1.PageInfo.Margin.Left = 30;
section1.PageInfo.Margin.Right = 30;
section1.PageInfo.PageHeight = PageSize.LetterHeight;
section1.PageInfo.PageWidth = PageSize.LetterWidth;
section1.IsLandscape = true;

HeaderFooter headerTitle;
Text textTitle;

//CreateHeader
headerTitle = new HeaderFooter(section1);
section1.OddHeader = section1.EvenHeader = headerTitle;
headerTitle.Margin.Top = 15;
headerTitle.Margin.Bottom = 10;

//Create the Title text
textTitle = new Text("This is the First Section Title\nSection One\n\n");
textTitle.TextInfo.Alignment = AlignmentType.Center;
headerTitle.Paragraphs.Add(textTitle);
//Add Header table
headerTitle.Paragraphs.Add(headerTable);

Text text = new Text("This is the 1st Section");
//section3.Paragraphs.Add(text3);
section1.AddParagraph(text);

//create another section
Section section2 = 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
headerTitle = new HeaderFooter(section2);
section2.OddHeader = section2.EvenHeader = headerTitle;
headerTitle.Margin.Top = 15;
headerTitle.Margin.Bottom = 10;

//Create the Title text
textTitle = new Text("This is the Second Section Title\nSection Two\n\n");
textTitle.TextInfo.Alignment = AlignmentType.Center;
headerTitle.Paragraphs.Add(textTitle);
//Add Header table
headerTitle.Paragraphs.Add(headerTable);

for (int i = 0; i < 100; i++)
{
Text text1 = new Text(String.Format("Row: {0}",i.ToString()));
section2.AddParagraph(text1);
}

//create another section
Section section3 = pdfDoc.Sections.Add();
section3.PageInfo.Margin.Top = 30;
section3.PageInfo.Margin.Bottom = 30;
section3.PageInfo.Margin.Left = 30;
section3.PageInfo.Margin.Right = 30;
section3.PageInfo.PageHeight = PageSize.LetterHeight;
section3.PageInfo.PageWidth = PageSize.LetterWidth;
section3.IsLandscape = true;

//CreateHeader
headerTitle = new HeaderFooter(section3);
section3.OddHeader = section2.EvenHeader = headerTitle;
headerTitle.Margin.Top = 15;
headerTitle.Margin.Bottom = 10;

//Create the Title text
textTitle = new Text("This is the Third Section Title\nSection Three\n\n");
textTitle.TextInfo.Alignment = AlignmentType.Center;
headerTitle.Paragraphs.Add(textTitle);
//Add Header table
headerTitle.Paragraphs.Add(headerTable);

Text text3 = new Text("This is the 3rd Section");
section3.AddParagraph(text3);

pdfDoc.Close();
pdfStream.Close();

Dear Gibsoju,

Thank you for considering Aspose.

Vertical alignment is not properly supported in Direct-to-File mode. If possible, please use normal mode for the current time. I will try to solve this problem in the next one or two hotfix.