Centering table after page break

I am having trouble with a table not staying centered after a page break. At first i had trouble centering the elements properly so I but them all in a larger table with 3 columns and put all the centered elements in the middle column. This looks great on the first page but if a table goes past the page break the second portion of the table is pushed to the right and flows off the page.
Attached is a sample so you can get a better idea of what I’m talking about. Notice on page 6 to 7 how it shifts. Everything is done in code there is no xml or word doc that its built from.
The elements are all centered before adding to the container table the alignment on the container table is not set, when i tried to set that to centered it pushed everything off the right hand side of the page.
Any ideas to fix this easily, I have a customer looking to have this report ASAP.


Thanks
Ray

Hello Ray,

I’ve tried to reproduce the problem using the following code snippet but I am unable to notice it. I’ve tested the scenario using Aspose.Pdf 4.0.0.0. The resultant PDF that I’ve generated is in attachment, please take a look.

Can you please test the following code snippet at your environment? In case you still notice the same problem, please share the version information of Aspose.Pdf and the code snippet that you are using, so that we can test it at our end.

We apologize for your inconvenience.

[C#]

// New a pdf object
Aspose.Pdf.Pdf pdf11 = new Aspose.Pdf.Pdf();

// Create PDF Section object.
Aspose.Pdf.Section sec1 = pdf11.Sections.Add();

//Instantiate a table object
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();

//Add the table in paragraphs collection of the desired section
sec1.Paragraphs.Add(tab1);

//Set with column widths of the table
tab1.ColumnWidths = "60 60 60 60 100 60";

//Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.1F);

//Set table border using another customized BorderInfo object
tab1.Border = new BorderInfo((int)BorderSide.All, 1F);

//Create MarginInfo object and set its left, bottom, right and top margins
MarginInfo margin = new MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;

//Set the default cell padding to the MarginInfo object
tab1.DefaultCellPadding = margin;
tab1.IsFirstRowRepeated = true;

//Create rows in the table and then cells in the rows
Row row1 = tab1.Rows.Add();
// set the background color for the first row
row1.BackgroundColor = new Aspose.Pdf.Color("Silver");
// set the alignment of the row elements as center alligned
row1.DefaultCellTextInfo.Alignment = Aspose.Pdf.AlignmentType.Center;
row1.Cells.Add("Question #");
row1.Cells.Add("Correct Answer");
row1.Cells.Add("Incorrect Answer");
row1.Cells.Add("Correct/ Incorrect");
row1.Cells.Add("Standard");
row1.Cells.Add("Strands");

for (int i = 0; i <= 50; i++)
      {
      Row row2 = tab1.Rows.Add();
      row2.DefaultCellTextInfo.Alignment = Aspose.Pdf.AlignmentType.Center;
      row2.Cells.Add("item1");
      row2.Cells.Add("item2");
      row2.Cells.Add("item3");
      row2.Cells.Add("item4");
      row2.Cells.Add("item5");
      row2.Cells.Add("item6");
      }

pdf11.Save("D:\pdftest\Table_Issue.pdf");