Posted by a ceTe Software moderator
Hello,
Yes, you can dynamically calculate the X position to middle the table in the page. You can get the midpoint of the page and table by dividing the width of respective elements by 2. Then calculate the X position for the table using these values. Below is the code sample.
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
Table2 table = new Table2(0, 0, 210, 100);
Column2 col1 = table.Columns.Add(100);
Column2 col2 = table.Columns.Add(100);
Row2 row1 = table.Rows.Add();
Cell2 cellR1C1 = row1.Cells.Add("Some text in R1C1");
Cell2 cellR1C2 = row1.Cells.Add("Some text in R1C2");
Row2 row2 = table.Rows.Add();
Cell2 cellR2C1 = row2.Cells.Add("Some text in R2C1");
Cell2 cellR2C2 = row2.Cells.Add("Some text in R2C2");
table.Height = table.GetRequiredHeight();
float pageMid = page.Dimensions.Body.Width / 2;
float tableMd = table.Width/2;
float xPos = pageMid - tableMd;
table.X = xPos;
page.Elements.Add(table);
document.Draw(@"C:\Temp\Mydocument.pdf");
Thanks,
ceTe Software Support Team